Node.js internals
The 4 parts of Node.js Architecture

Node.js internals

I have been using Node.js for my Flutter apps but never delved into the depths of its architecture. I am taking a course that describes the internal nature of Node.js.

Node.js basically has 4 major parts,

1. The V8 engine that browsers already had for running Javascript.

2. The Node.js apis (I mean the process, event and other modules) which are in javascript

3. The Node.js bindings which are in C++.

4. The libuv library which is in C.


As we know, the V8 engine runs basic Javascript code. The Node.js apis are the modules you normally use to perform special tasks. Let's consider fs module for example which is for file I/O. Since Node.js is open source, we can go and view what its internals are. Go to this link https://lnkd.in/dJ-uYYZH and open the lib folder. Inside the lib folder you'll find fs.js file. This is the Node.js api I am talking about. Then come the Node.js bindings. To understand them consider one function of the fs module for example. Consider the open() function in fs.js for now. Use ctrl+f to find it in the file. Inside the body of function, you will find a binding.open() function. This function is important as it is triggering the C++ binding in nodejs to do the opening. In the same github repository go to the src folder instead of the lib folder and find a node_file.cc file. This has the bindings for fs module. When you do ctrl+f to find the Open() function there, you'll see a reference of uv_fs_open inside this function. What is it? It's a reference to the libuv library which is the 4th part that i mentioned above. For the last part of this example, go to libuv repository on github here https://lnkd.in/dmFv9eev. Go to the src folder and open win folder for now. Find a fs.c there, open it and use ctrl+f to find fs__open(). You will find a function that actually does the work of dealing with the file. This is C code and the lowest level of hierarchy which was triggered all the way up from the second part which was the fs module.


Posted this because I found this fascinating. No matter how much I try C++ and C come somewhere to haunt me🥲.

it's libuv that gives nodejs that thread pool it would die without haha

To view or add a comment, sign in

Others also viewed

Explore content categories