Node Js Internal Structure Part-1

Abhishek Savani
3 min readApr 19, 2020

--

In this article, we discuss some internal structure of node js. Here we getting an idea of how node works internally. here you get batter idea how node js work internally. after understanding the internal structure of node js you will be able to leverage that knowledge to write some more performant code inside your node js application.

Basic internal architecture of node js

Here is a basic diagram of the node internal structure.

  1. Javascript code we write: The javaScript code which you and I write.
  2. Node js: When we run node js file (index.js)using a command line like node index.js that time we invoking node js project.
    Now just like any other javascript project node js internally has a collection of dependencies that uses actually execute your code.
  3. V8 & Libuv: The most important dependencies are V8 & libuv which we8 discuss more in this article.

V8 Project

V8 project is an open-source javascript engine which is created by Google. The Purpose of this project execute javascript code outside of the browser. So that's why we run our javascript code in terminal.

Libuv Project

The libuv project in c++ open source project that gives node access the operating systems. like file system, networking and also handle some aspect of concurrency as well.

So now we have a question why we use node ? why we don't directly use V8 and libuv ?

So here is the answer. the first thing we need to understand is that internally some of these libraries are not javascript code.

percentage of languages use to develop node js libraries

The v8 project is like 70% c++ code and libuv over here is 100% c++ code. so as javascript developer you don't want to be writing c++ code all day. you want to write javascript code and just have it work.

So that's the purpose of the node js give us to nice interface to relate our javascript side of the application to the actual c++ that's running on our computer to actually interpret and execute out javascript code.

Another thing is node does is provide a series of wrappers and a very unified inconsistent API for us to use inside of our projects.

So for example node implement HTTP module and fs, path, crypto all these modules right here have very consistent API. And they all ultimately a functionality that is mostly implemented inside of libuv project.

So again you probably don't want to get access to direct c++ code. You want to require some javascript function and use a javascript function inside of your codebase. So by making use of node you don't have to work with all the c++ that exist inside of libuv itself.

So in Node Js Internal Structure Part-2 will describe how node js use C++ code.

👉 Node Js Internal Structure Part-2

👉 Node Js Internal Structure Part-3

--

--