NodeJS Introduction


In this tutorial, we will discuss about NodeJS, Architecture of NodeJs, advantage and disadvantage of NodeJS.

  1. NodeJS Introduction
  2. NodeJs Architecture
  3. Advantage of NodeJS
  4. Disadvantage of NodeJS

NodeJS Introduction

  1. Ryan Dahl developed Node JS in the year 2009
  2. NodeJS is free of cost (Open Source) and cross-platform runtime environment for executing JavaScript code outside a browser.
  3. NodeJS js is not a programming language. It is a runtime environment. Node js uses the javascript for the frontend programming interface.
  4. NodeJS can be runs on various platforms like Windows, Linux, Unix, Mac OS X, etc.
  5. If we create a .JS file in our system and want to run that file we can use node.js. So it provides runtime enviroment.
  6. NodeJS is commonly used for Backend Social Networking, Sinple page application, Chat Applications, Data Streaming etc.
  7. NodeJS runs single threaded, non blocking, asynchronous programming which is very memory efficient.
  8. NodeJS eliminates the waiting, and simply continues with the next request.
  9. There are many companies which use NodeJS like Netflix, NASA, Trello, PayPal, LinkedIn, Walmart, Uber, Twitter, Yahoo, eBay, GoDaddy. Google uses NodeJS in its search indexing service.
  10. Node JS can be described as JavaScript that has been given the ability to run on the computer, instead of the browser. This is made possible by the V8 JavaScript runtime engine. 
  11. Node.js is built on the V8 engine of Google. It is the fastest javascript engine. The V8 engine converts the javascript code into the machine code, which the computer understands. The result is then generated and returned to node.js.
  12. Node.js uses asynchronous programming.

Problem with A Typical Web application

Assigning Independent Threads to Each Request is an Expensive Task. In technologies like C# and Java, each request is processed with an independent Thread. The problem with the approach is that Server has Fixed No of Threads in the Thread Pool. Therefore at any moment of time, Maximum Request processed are equal to number of Threads in Thread Pool.

NodeJS Architecture

The following diagram show the how NodeJS handle multiple concurrent request using single-threaded event loop architecture.

NodeJS Introduction

Components of the Node.js Architecture:

  • Requests - User send the requests to the server can be either blocking (complex or heavy) or non-blocking (simple).
  • Node.js Server - The Node.js server accepts user requests, processes them and returns results to the users.
  • Event Queue - Event Queue is used to store the incoming client requests and pass them sequentially to the Event Loop.
  • Thread Pool - The Thread pool in a Node.js server contains the threads that are available for performing operations required to process requests.
  • Event Loop - Event Loop receives requests from the Event Queue and sends out the responses to the clients.
  • External Resources - In order to handle blocking client requests, external resources are used. They can be of any type ( computation, storage,etc).

In the above image,

when the request hits the node server, it will go to the event loop through the event queue. The event loop will now check whether the task is heavy, like operations dealing with files or network-related operations. If the task is heavy it will offload it to the thread pool, where the thread pool will execute the task separately. it will not block our event loop, and the event loop can perform all the less complex tasks. So Asynchronous and Non-blocking of I/O operations features enhance the scalability, performance, and throughput of Node.js web applications.

Node.js Advantages

  1. V8 JS engine complies with Javascript code directly into the machine code that enhance performance for Real-time Applications.
  2. Easy Scalability for Modern Applications
  3. Large Community Support to Simplify Development. Nodejs is supported on Github which makes it super easy and fast to develop and support the framework.
  4. Easy to Learn and Quick to Adapt.
  5. Nodejs use single language on front-end and back-end Javascript.
  6. Nodejs is compatible with desktop, mobile, and web development for Mac, Windows, and Linux.
  7. Nodejs along with npm libraries Boosts development speed
  8. Helps in Building Cross-Platform Applications

Node.js Disadvantages

  1. Node.js Reduces performance when handling Heavy or complex Computing Tasks
  2. Node.js Asynchronous Programming Model makes it difficult to maintain code
  3. High demand with a few Experienced Node.js Developers in the market.

Prev Next