Let's dive into the world of Node.JS !!!

Let's dive into the world of Node.JS !!!

While everyone is going mad about Node.js, let's understand why the developers and great IT giants across the globe are induced towards Node.js. Do you know Netflix, Uber, LinkedIn, and even NASA is part of the Node.js fanclub !!! Also, "PayPal" which is world’s largest and the most trusted services for financial transactions uses Node.JS as one of the technology. So, what is it so special about Node.js and its role in web app development? Let's dive into the world of Node.JS to find out the answer of this question .....

What is Node.JS ?

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the Chrome's V8 engine. It is basically used for building fast and scalable real time network applications.

How does it Works ?

  • Traditional web-serving techniques where each connection (request) spawns a new thread, taking up system RAM and eventually maxing-out the available memory. Also in traditional systems "Multi-threaded request-response” architecture is an event loop which is much slower and unable to handle multiple concurrent threads at a time.

  • Unlike traditional techniques Node.js operates on a single-thread, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections held in the event loop.

Traditional Vs NodeJS.png

Node.JS Architecture

Node.js uses the “Single Threaded Event Loop” architecture to handle multiple concurrent clients. Node.js Processing Model is based on the JavaScript event-based model along with the JavaScript callback mechanism.

NodeJS Architecture.png

Now let’s understand each part of the Node.js architecture and the workflow of a web server developed using Node.js.

  • Requests - Incoming requests can be blocking (complex) or non-blocking (simple), depending upon the tasks that a user wants to perform in a web application.
  • Node.js Server - Node.js server is a server-side platform that take requests from users, processes those requests, and returns the response to the corresponding requests.
  • V8 Engine - The V8 library provides Node.js with a JavaScript engine, which Node.js controls via the V8 C++ API. V8 is maintained by Google, for use in Chrome.
  • LIBUV - Libuv is a C library that is used to abstract non-blocking I/O operations to a consistent interface across the platform. It provides mechanisms to handle file system, DNS, network, child processes, pipes etc. It also includes a thread pool for offloading work for some things that can't be done asynchronously at the operating system level.
  • Event Queue - Event Queue in a Node.js server stores incoming client requests and passes those requests one-by-one into the Event Loop.
  • Event Loop - Event Loop indefinitely receives requests and processes them, and then returns the responses to corresponding clients.
  • Worker Threads - Workers (threads) are useful for performing CPU-intensive JavaScript operations.

We should not miss to check what's npm?

  • npm is the package manager/registry for Node.js. It was created in 2009 as an open source project to help JavaScript developers easily share packaged modules of code.

  • npm Registry is a public collection of packages of open-source code for Node.js, front-end web apps, mobile apps, robots, routers, and countless other needs of the JavaScript community. The most amazing thing to know is :

npm is the World's Largest Software Registry !!!!

  • npm contains millions of downloadable libraries for specific requirement. And the greatness of npm lies in the point that, all the libraries are absolutely free of cost. These libraries are getting bigger rapidly, making the Node.js community stronger day by day.

Below are the some of the most popular npm packages

Where we can use NodeJS ?

  • Internet of Things (IoT) - NodeJS has less memory requirements so it can be easily integrated with controller boards like Arduino.
  • Real time chat applications - If you choose to install the WebSockets on the server-side as well as on the client-side, Node.js is capable of carrying out real-time messaging with lower latency and faster data transfer. This ability can be used to build chat apps at a better level.
  • Single Page Applications - Node.js is written in the same language (JavaScript) as used to build SPAs. This makes the work of developers quite simple because they can use the same language and data structure on the server and the client-side.
  • Apps required for performing file operations - Node JS has one beautiful inbuilt module that is "fs" which makes the file operations like read, write, delete etc very easy for the developer.

Features that may attract you to Node.JS

  • High performance - Node.js runs on Google V8 JS engine that complies with JavaScript code directly into the machine code. This makes it resource efficient as well as accelerates the framework’s speed.
  • Fast development process & Removed need for different languages - Node.js offers a cocktail of similar languages on front-end and back-end JavaScript. It is actually more accessible and flexible than it sounds. It makes the entire web app development cycle robust and seamless for developers and enterprises.
  • Non-blocking I/O paradigm - Blocking refers to operations that block further execution until that operation finishes while non-blocking refers to code that doesn’t block execution. Or we can also say that, blocking is when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes. Blocking methods execute synchronously while non-blocking methods execute asynchronously. NodeJS do provide a feature of synchronous processing tallows requests to be processed without blocking (non-blocking I/O) the thread. So after a request is processed, it can push out a callback and continue serving requests. That helps Node.JS make the most of single threading, resulting in short response time and concurrent processing.
  • High Scalability - Node.js applications are easily scalable, vertically and horizontal. While vertical scaling lets you add more resources to the current nodes, horizontal scaling enables you to add new nodes quicker. Also the apps built in NodeJS can handle increasing number of connections.
  • Gigantic open-source community and NPM repository (More than 1600000 packages) - A large number of software developers & many active Node.js geeks are constantly contributing to the evolving Node.js community to support the developers across the globe.

nodejs advantages.png

Like every programming platform/language, this one too has some cons !

  • NodeJS shouldn't be used if you are going to develop application for heavy computation.
  • Node’s relational database support tools are not up to the expected level when compared to other languages. This makes Node an undesirable for use cases with relational databases.

Thanks for reading !!!

Feel free to share your views in the comments section below. Please don't forget to check my other blogs :)

You can connect with me on Linkedin

Did you find this article valuable?

Support Learn with HJ by becoming a sponsor. Any amount is appreciated!