As we know that Node JS is Asynchronous and Event Driven Javascript Runtime used to build scalable applications. But how does Node JS works under the hood 🤔, that is still not clear. To understand Node JS internal functionalities, we should learn Node JS Architecture and Node JS Core Functionalities first.

Node JS Developers write their program in Javascript or TypeScript. Internally it is interpreted/compiled by V8 engine. But how does node js do input output, i.e I/O. How file system works. How Node JS handle requests through HTTP Modules, how files are compressed Node, etc.


Node JS Architecture

Node JS use single thread and Event Driven Architecture which makes it both Fast and Highly efficient for handling concurrent connections.

Node JS Architecture Explained
Node JS Architecture Explained

Node JS Core

The core of Node JS includes mainly three blocks.

  1. V8
  2. Libuv
  3. Event Loop
Node JS System Explained
Node JS System Explained

chrome v8 engine
V8 Logo

V8

V8 Engine is Google's Open Source and High Performance JavaScript Engine used in Chrome, Edge, Chromium, Brave and Opera Browsers. V8 is written in C++.

JavaScript was build as Scripting Language, but V8 use a interpreter to read code and finally a Run Time ( i.e. JIT ) compiler for finale execution. This process can execute JavaScript faster as compared to traditional interpreters.


Libuv

Libuv is a library written in C used for Asynchronous Input Output operation on File system and networks. Libuv performs all low level Non Blocking I/O operations.

As we know that JavaScript is single thread. But Libuv use Thread Pool and Event loop which can use upto Four threads for high performance and non blocking Input Output operations.


c-ares

c-ares is a C library used to handle Asynchronous DNS requests. c-ares provides interfaces for asynchronous queries while trying to abstract the intricacies of the underlying DNS protocol. Its also protect from common DNS vulnerabilities.

The DNS Lookup works asynchronous without blocking the event loop offering smooth operation.


http-parser

http parser is used to parse HTTP requests in Node JS application, Node JS use llhttp HTTP Parser which is powerful and efficient.c


Crypto

Crypto is a toolkit for cryptography functionalities. Its can be used for Hashing, HMAC, Cipher, Decipher, Digital Signatures and Random Numbers generations.


zlib

zlib is a powerful compression and decompression library used in Node JS. Zlib create GZIP compression which compress files during transfer from frontend to backend or backend to frontend. For Example, a jQuery file which is 89.5kb compressed to just 31kb during transfer.