Node and Express simplified

Node and Express simplified

·

4 min read

I recently started venturing into Node.js and one of the very first explanations for What is node.js? I found online is ,

"Node.js is a packaged compilation of V8 JavaScript engine, the libuv platform abstraction layer, and a core library, which is itself primarily written in JavaScript."

Even though there are some familiar terms, on the whole it's jargon for me.

So, here is my take on simplifying what node and express is.

Why:

  1. Javascript, though capable of doing amazing things , is confined to a web browser and client side programming. To use it on the server side, we need Javascript outside the browser.
  2. There are many languages that can be used on the server side like Java,PHP,C# etc..but all of them are multi-threaded and it becomes complicated to use Javascript with them as javascript is single-threaded.

What:

  • For Javascript to work on browsers, we need Javascript engine. Different browsers have different engines like
    { Google : V8 engine , Mozilla : SpiderMonkey , Safari : JavascriptCore , InternetExplorer : Chakra }
    All these browsers provide a run-time environment for Javascript which converts our code to machine language and executes the code.
  • Node is nothing but Google's V8 engine embedded in a C++ program which acts as run-time environment for Javascript outside the browser.
  • Node is Asynchronous and single-threaded in nature similar to Javascript which makes it easier to use javascipt on the server-side.

How:

Asynchronous and single-thread:
To visualize this, let's consider a café.
Like every morning, you enter the café, you place your order to the barista and you take a seat. When your order is ready, the barista informs you and you collect your order.

This is the exact of working of Node.

  1. The client(you) sends a request(your order) to the server(chef) through node(barista).
  2. Node receives that request and puts in a "Event Queue".
  3. Every request in the event queue is processed one-by-one by the server.
  4. Once the request is processed, node prepares a response and executes a call back function and sends it back to the client. Javascript.png

Express:

  • Like Django for Python, React for Javascript, Express is a framework for Node.js which is free and open-sourced.
  • It allows us to simplify the code by providing secure features and facilitates the development of Node based applications.

    Thank you reading 💗

    Connect with me on Twitter or Github