Basic Concepts in Node.js
Published: 2021-10-25 14:10:42

A web application that is able to send in hundreds of requests by the second to a server that can only process one request at a time. In this article, we’ll cover the basic things you need to know about Node.JS, and why it has such an important role in today’s server side industry. 


## What is Node JS and why should you use it.

Node JS is an open-source JavaScript based server side programming platform built on Chromes V8 JavaScript engine, which means that the engine that compiles JavaScript in a web browser is also the engine that runs Node.Js in its core, which is why it is so fast, especially for the web applications. 
Netflix, Uber, LinkedIn, and Paypal all use the Node.Js as a serverside platform to build modern, and dependable web applications. Its event driven architecture is ideal for applications with high I/O (inputs and outputs) because of its single thread characteristics combined with a multi thread platform that runs in the background, allowing it to serve more clients with less hardware, resulting in higher performance at lower costs. 




## Features of Node.JS

The following are some very important features that makes Node.js the first choice of software architects, that gives it it's advantage above other technologies for the purpose of back-end web app development.

## Non-Blocking I/O

The non-blocking method takes an input and asynchronously returns an output. In other words, it allows a server to receive numerous requests without causing the application to be blocked while the response is processed in the background.


## Single Thread

With its single thread feature, Node.js can handle several events at the same time by delegating asynchronous operations to a multi thread platform, allowing only one thread to handle inputs and outputs.

This feature makes it lightweight, and efficient by requiring little memory and infrastructure to handle numerous queries.


## Event-Driven. 

Node.js is an event-driven technology, which means that events control the server-side platform's control flow. As a result, when a Node application starts, an event listener named Event Loop starts waiting for events and doesn't do anything until it receives them.


Alternatively, it's the equivalent of having a super-efficient waiter taking orders until the restaurant closes.


## Event-based Node.js

Node Package Manager (version 2.4) is a tool for managing nodes in a network.
The world's largest free and open source collection of functions, Node Package Manager, may be readily imported and used in any Node application. All of this means that Node Package Manager will have any tools an application requires.


## Buffering isn't Necessary

Node.js apps don't buffer data, which cuts down on the time it takes to upload large media like videos or audios. Which alternatively means,  it just outputs data in pieces.
A user can, for example, watch videos without being interrupted.

**Scalability** is a core Node characteristic, as it has a high capacity for handling large amounts of requests asynchronously with low infrastructure thanks to its architecture, which runs on a single thread combined with a multi thread platform, allowing it to receive thousands of events at the same time.

# Node.js Architecture 

The architecture of Node.js is made up of three core components that work together like an event processing factory. So, to make it easier to grasp how these pieces interact with one another, I'll show you an example of a Node.js REST API.

Let's imagine a client sends this application multiple requests.

## Event Queue 

As soon as these requests arrive to the program, they are sent to the Event Queue, which is a queue where all the application's events are placed initially, and where they wait to be sent to the main thread, the Event Loop, to be processed.

## Event Loop 2

When a request (Blocking Operation) hits the Event Loop, which is a single thread platform that uses the V8 Engine to compile JavaScript at its core, it is delegated to the Thread Pool platform to be processed in the background. As a result of this architectural flow, the main thread is free to process other events once again.


## Thread pool

The request (Blocking Operation) is handled asynchronously in the background until it's done and ready to be returned to the Thread Pool, which is a multi-thread platform that runs a library called libuv and has C++ at its core.

# Conclusion

Node.js has grown in popularity and is now being used and fully utilized by numerous enterprises and startups. 
In today's hyper-connected world, a technology that can scale quickly while requiring minimal infrastructure is undoubtedly a key player to watch.
With this article, I hope you have a better knowledge of how Node.js works.