DEV Community

Cover image for Simplistic Dive into Node.js Internals
Odap
Odap

Posted on • Updated on

Simplistic Dive into Node.js Internals

I-Introduction



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.


II- Node.js Internals :



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.



1- The V8 Engine :

V8 engine logo



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.



2- Node.js APIs :

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.



3- Node.js Bindings :

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.



4- The libuv :

libuv




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.

Top comments (0)