Simplistic Dive into Node.js Internals 
Tags: node, javascript, programming, productivity
Published: 2022-01-25 11:31:04


## I-Introduction
<br/>
Node.js is one of the very popular JavaScript runtimes in the modern world. Why is that? , Well node.js differ with an asynchronous architecture that not all the server side frameworks have, in fact , most of the frameworks are based on a synchronous architecture which makes it hard to implement asynchronous I/O resulting in a poor scaling.

Node.js with a set of outbreaking internals have changed the game and introduced the world to the full-stack development  thanks to the  release of V8 engine by Google Chrome back in 2008.
In this article I will try to guide you through the internals of node.js and make it simple and beginner friendly.
<br/><br/>

## II- Node.js Internals :
<br/>
We have mainly four essential node.js parts that we should absolutely know : the V8 JavaScript engine, the Node.js APIs, node.js Bindings and finally the Libuv. lets have a look at each one apart.
<br/>
<br/>
###  1- The V8 Engine :
<br/>

![V8 engine logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5npzrg4s6qagvbi4r6q.png)

<br/>
Have you ever wondered how does a chrome browser understand JavaScript ? well, the browser does not understand or even know what JavaScript is, instead it's The V8 engine that understands and executes our JavaScript code.

So, when we open our browser to run some code we are actually trying to implicitly use the V8 engine.

Similarly, the V8 engine is the part of node.js that understands JavaScript and is able to execute our code.

So, to keep it as simple as possible, the V8 engine is the part that build our JavaScript runtime.
<br/>
<br/>
###  2- Node.js APIs :
<br/>

 As we established in the section above, our JavaScript code is executed inside the v8 engine as it provide a rich environment to do so.

However, There are many functionalities that can't be run inside our environment. For example, sending an http request is a task V8 engine can't do by itself.

node.js APIs provide these additional functionalities to make it possible to do things like http requests, working with files or even encrypting data etc..

Here comes the trickiest part,node.js APIs provide a range of functions that are not just JavaScript code, but also a lower level,machine close code like C and C++ ,we'll talk about that in the next part.

In short, node.js APIs are additional functionalities that makes it possible to do things our V8 engine can't do.
<br/>
<br/>
### 3- Node.js Bindings :
<br/>

This a very interesting part, remember when I talked about the 
node.js apis calling in some C/C++ functions, well node.js bindings is what make it possible to attach our JavaScript code to low level languages such as C/C++, this attachment is what we refer to as "binding".

Node.js bindings have some depth in its inner workings, but to keep it as simple as possible we'll think of it as the part of Node.js that bind JavaScript with low level languages.
<br/>
<br/>
### 4- The libuv :
<br/><br/>

![libuv](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ujopigbde1rftw9jjpl.png)
<br/>
<br/>
libuv is a C library specifically designed to handle asynchronous
I/O and enforce an event driven style offering core utilities like timers, non-blocking networking support, asynchronous file system access etc. 

libuv is at the core of node.js internals for the main reason that JavaScript is a single-threaded programming language which means that it would have trouble dealing with blocking functions, So basically libuv solves one of the major issues facing node.js which is asynchronous operations.