Original text
Rate this translation
Your feedback will be used to help improve Google Translate

Cookie Consent

By clicking “Accept Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage and assist in our marketing efforts. More info

General Published on: Fri Feb 10 2023

Understanding NodeJS and its Architecture

We all have heard of JavaScript, a pre-dominant client-side programming language used by almost all websites. But what about server-side programming?

Let me introduce you to Node.js. But what exactly is Node.js?

What is NodeJS?

It’s important to know that NodeJS is not a JavaScript framework. Node.js is an open-source runtime environment for javascript. It is built on Chrome’s V8 JavaScript engine. Node.js can run on various cross platforms such as Linux, Windows, macOS, and mobile platforms.

Programs written in JavaScript can be run both on the server and client-side. To put it simply, Node.js is a programming language that lets developers run JavaScript on the backend.

Why is NodeJS special?

Node executes reading/writing to the file system, network connections, and database lightning fast. It allows developers to build fast and highly scalable network applications capable of handling bulk amounts of simultaneous connections having high throughput.

Typically, Node.js uses a basic event-driven architecture. Everything executed on it, including every operation and call, is a series of asynchronous callbacks. This enables Node to run on a single thread, unlike other web technologies where a new thread is spawned for every client request. This makes it light-in-weight and forms the foundation of Node’s non-blocking I/O feature. 

All the other technology stacks necessarily include two languages – one on the client-side and the other on the server-side. On the contrary, Node uses only JavaScript for the client and server-side. Thus, web developers must interact only in a single language across all layers. Adding to it, this can be reused repeatedly for future communications. 

In Node.JS for functions callback hell, we can say goodbye with Promises of async and await libraries.

Node is a very High-Performance language. With Node, the traffic occurring on the servers and CPU utilization are also gets reduced. LinkedIn, the global networking site, moved from Ruby to Node to handle its mobile traffic and reduced the number of servers from 30 to 3, i.e., an almost 90% reduction. 

 We can also say Node.JS is very popular for its libraries. It has many libraries, making the developer’s work easier. Node has an NPM that manages all the libraries and packages. NPM, with its simple structure, helped the ecosystem of Node.js increase, and now the NPM registry hosts over 1,000,000 open source packages you can freely use. 

How popular NodeJS is? 

According to Stack Overflow’s 2021 developer survey, Node.js is the 6th most popular technology among programmers. Node.js is also a part of the MEAN, MERN, and MEVN stacks.

Node.js Architecture

In Node.js, multiple concurrent clients are handled by the “Single Threaded Event Loop” architecture. A Node.js Processing Model is based on the JavaScript event model and the JavaScript callback mechanism.

Now let’s understand each part of the Node.js architecture.

 

Image Source: Simplilearn.com

Parts of the Node.js Architecture:

Incoming requests – It can be categorized into two types, blocking (complex) or non-blocking (simple), depending on the tasks a user wants to perform in a web application.

Node.js Server – This is a server-side platform that receives requests from users, processes those requests, and responds accordingly.

Event Queue – Event Queue in a Node.js server stores incoming client requests and passes those requests one-by-one into the Event Loop

Thread Pool – This pool contains all the threads available for performing some tasks required by clients

Event Loop – Event Loop processes the requests received and then returns the responses to corresponding clients.

External Resources: External resources are needed to handle blocked requests from clients. These resources can be for computation, data storage, etc.

  • Express.JS
  • Meteor.JS
  • Socket.io
  • Nest.JS
  • Sails.JS
  • Total.JS
  • Hapi.JS
  • Feather.JS
  • LoopBack.JS
  • Adonis.JS
  • Derby.JS

Benefits of NodeJS

  • The major benefit of node.js is, using JavaScript in both the frontend and backend. So, it becomes easier to keep them in sync because a single language is used on both sides of applications.
  • Since Node.js is an event-based platform, it is highly suited for real-time applications requiring continuous data updates. Furthermore, the non-blocking input-output model contributes to the performance enhancement.
  • If you are looking to develop scalable and lightweight web applications, then in this case you can choose Node.js. It has a huge community that continuously contributed to its improvements.
  • The introduction of node modules made it easier for developers to reuse code and use prebuilt modules.