Explain the working of Node.js
Last Updated :
27 May, 2024
Welcome to the world of Node.js, an open-source runtime environment that has transformed the landscape of backend development. Traditionally, JavaScript was confined for frontend development, powering user interactions on the browser. However, with the advent of Node.js, JavaScript has broken free from these chains and now reigns on the server-side as well, enabling full-stack development with a single language. Node.js runs on chrome v8 engine which converts javascript code into machine code, it is highly scalable, lightweight, fast, and data-intensive.
Working of Node.js
Node.js accepts the request from the clients and sends the response, while working with the request node.js handles them with a single thread. To operate I/O operations or requests node.js use the concept of threads. Thread is a sequence of instructions that the server needs to perform. It runs parallel on the server to provide the information to multiple clients. Node.js is an event loop single-threaded language. It can handle concurrent requests with a single thread without blocking it for one request.
Node.js basically works on two concept
- Asynchronous
- Non-blocking I/O
1. Non-blocking I/o
Non-blocking i/o means working with multiple requests without blocking the thread for a single request. I/O basically interacts with external systems such as files, databases. Node.js is not used for CPU-intensive work means for calculations, video processing because a single thread cannot handle the CPU works.
2. Asynchronous
Asynchronous is executing a callback function. The moment we get the response from the other server or database it will execute a callback function. Callback functions are called as soon as some work is finished and this is because the node.js uses an event-driven architecture. The single thread doesn’t work with the request instead it sends the request to another system which resolves the request and it is accessible for another request.
To implement the concept of the system to handle the request node.js uses the concept of Libuv.
Libuv is an open-source library built-in C. It has a strong focus on asynchronous and I/O, this gives node access to the underlying computer operating system, file system, and networking.
Libuv implements two extremely important features of node.js
Event loop:
The event loop contains a single thread and is responsible for handling easy tasks like executing callbacks and network I/O. When the program is to initialize all the top-level code is executed, the code is not in the callback function. All the applications code that is inside callback functions will run in the event loop. EventLoop is the heart of node.js. When we start our node application the event loop starts running right away. Most of the work is done in the event loop.
Nodejs use event-driven-architecture.
- Events are emitted.
- Event loop picks them up.
- Callbacks are called.
Event queue
As soon as the request is sent the thread places the request into a queue. It is known as an event queue. The process like app receiving HTTP request or server or a timer will emit event as soon as they are done with the work and event loop will pick up these events and call the callback functions that are associated with each event and response is sent to the client.
The event loop is an indefinite loop that continuously receives the request and processes them. It checks the queue and waits for the incoming request indefinitely.
Thread pool
Though node.js is single-threaded it internally maintains a thread pool. When non-blocking requests are accepted there are processed in an event loop, but while accepting blocking requests it checks for available threads in a thread pool, assigns a thread to the client’s request which is then processed and send back to the event loop, and response is sent to the respective client.
The thread pool size can be change:
process.env.UV_THREADPOOL_SIZE = 1;

Working of Node.js
Similar Reads
Working Process of Node.js
Node.js is an open-source and cross-platform runtime that build on top chrome's v8 JavaScript engine. Basically, now a days it is very popular. Many server uses node.js to run applications. Why it is so famous? There are mainly two features that make Node.js famous: Non blocking I/OAsynchronous Non
2 min read
Working with forms using Express.js in Node.js
In this article, we will be working with forms using ExpressJS in NodeJS. Using server side programming in Node.js, we can create forms where we can put certain parameters which upon filling gets stored in the database. Setting up environment: You can refer to this website for downloading Node.js. A
3 min read
Explain the Process Object in Node.js
In this article, we are going to explore about process object of Node.js in detail. The Process object in node.js is a global object that can be used in any module without requiring it in the environment. This object is useful in the perspective of getting the information related to the node.js envi
3 min read
Explain the use of crypto module in Node.js
In this article, we will explore the crypto module and what are its uses in Node.js. NodeJS supports a large number of third-party modules. These modules can be used for performing different kinds of tasks. The crypto module is also a 3rd party module that can be imported and used in NodeJS. This mo
3 min read
Node.js Worker Threads
Worker Threads in Node.js is useful for performing heavy JavaScript tasks. With the help of threads, Worker makes it easy to run javascript codes in parallel making it much faster and efficient. We can do heavy tasks without even disturbing the main thread. Worker threads were not introduced in the
2 min read
What is the role of assert in Node.js ?
Assert is a Node.js module that provides facilitates to writing the test and will not provide any output on the terminal when the test is in the process until any asserting error during the test. It provides various set assertion functions that can be used verifying constants. The assert module in m
2 min read
How to work with Node.js and JSON file ?
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. With node.js as backend, the developer can maintain a single codebase for an entire application in javaScript.JSON on the other hand, stands for JavaScript Object Notation. It is a lightweight format for storing and exchanging d
4 min read
Reading Path Parameters in Node.js
Path parameters are an essential part of RESTful APIs, allowing the server to capture values from the URL and use them in request handling. This capability is crucial for creating dynamic and flexible endpoints. In Node.js, especially when using frameworks like Express.js, handling path parameters i
2 min read
Explain the Mechanism of event loop in Node.js
JavaScript is a single-threaded, non-blocking, asynchronous language that uses the concept of event loop to make it work asynchronously even if it is single-threaded. Feature: The Event Loop is responsible for sending functions from the event queue to the Stack for processing when it becomes empty.
2 min read
What are the Key Features of Node.js ?
Node.js has gained immense popularity among developers for its ability to handle server-side operations efficiently and effectively. Built on Chrome's V8 JavaScript engine, Node.js is designed to build scalable and high-performance applications. Here, we explore the key features that make Node.js a
5 min read