Basic concepts of Node.js

#js #node

Node.js is a great technology aimed to process numerous asynchronous inputs and outputs, aiming to improve the application’s performance and the user experience.

This article will provide the basic concepts of Node.js, proving its importance in the modern world of server-side development.

What is Node.js?

Node.js is a JavaScript-based platform for server-side programming. It is open-sourced and built on Chome’s V8 JavaScript engine, fastening development processes, especially for web applications.

Reasons to choose Node.js

In the light of its single-thread characteristics and the background-running multi-thread platform, its event-driven architecture suits best applications with intense inputs and outputs ratio (I/O). Thus, it is perfect for performing more while spending less.

In addition to that, the platform provides even more great features for developers.

Non-blocking inputs and outputs

This means that the method is capable of receiving input and giving back output asynchronously. This means that the server may receive numerous requests and process the responses without blocking the application from running properly.

Single Thread

A single thread handles all inputs and outputs, making the platform lightweight and scalable while consuming less memory.

Event Drivenness

Being event-driven means that Node.js’s flow control is run by the occurrence of events. That means that once the Node.js application has been started, an event listener called Event Loop starts waiting for events, and it won’t stop until the application is shut down.

Platform’s Package Manager

The Node Package Manager is the world’s most extensive open-source library of functionalities, and it can be easily imported to and used in any Node-written application. Thus, any tool an application might need can be found in the library.

No Buffering

No data buffering fastens the process of uploading files. Node.js applications output the data in chunks, which remarkably improves user experience.

Scalability

Thanks to the previously mentioned single thread, the platform is highly capable of handling numerous requests asynchronously. The scalability of the platform is its core characteristic, which allows it to process thousands of events at a time.

Node.js Architecture

The architecture consists of three key elements. These are Event Queue, Event Loop, and Thread Pool.

Let’s take a brief look at this using a REST API developed in Node.js as an example.

So what happens first? Let’s say that a client sends a number of requests to the application.

Event Queue

Once the requests reach the application, they get to the Event Queue, where they are waiting to be processed to the Event Loop. The Event Queue is an actual queue where all the application events process to the Event Loop one by one.

Event Loop

Next, the requests reach Event Loop. That is a single-thread platform that is running the V8 Engine in its core in order to compile JavaScript. After that, the code is delegated to the next element, which is the Thread Pool. After that, Event Loop is available to handle new requests while the previous ones are processed further.

Thread Pool

Thread Pool is a multi-thread platform that has C++ in its core and runs a library called libuv. At this stage, a single request is processed in the background until its ready to be returned.

Previous Topic
React Native's Inner Life
Next Topic
Things You Need to Know About Software Development Life Cycle
We Love to Hear From You
For any support, sales, careers, or security inquiry please contact us!

    * - marked fields are required.