NodeJS Architecture: Relationship between libUV, V8 and JS
Components ownership:
Gives access to the operating system to perform tasks related to the filesystem or time scheduled tasks etc.
libuv is a multi-platform support library with a focus on asynchronous I/O. It was primarily developed for use by Node.js, but it’s also used by Luvit, Julia, pyuv, and others.
V8:
Compiles and executes JavaScript source code, handles memory allocation for objects, and garbage collects objects it no longer needs.
As of now V8 has moved away from JIT (Just In Time) compiler to interpreted
These are the main functionalities of the V8 engine :-
- Compiles and executes JS code
- Handling call stack
- Managing memory allocation for objects
- Garbage collection — of objects which are no longer in use
- Provide all the data types, operators, objects and functions
A JavaScript runtime built on Chrome’s V8 JavaScript engine.
The thing is that in the early days of web, Javascript was intended to run only on the browser for client-side interactions. But slowly and gradually (after Google’s v8 engine) people started using Javascript out of the browser and to replicate the browser environment outside an actual browser NodeJS was released.
NodeJS is proficient with internet fundamentals such as TCP, HTTP etc. which made it a good choice for writing server-side code as well.
Checkout nodejs repo to see the composition
See it in action:
Write a JS code and code run with --print-bytecode
with node command to see language being interpreted to machine code. Check out other detailed visualizations.
node --print-bytecode app.js
Try out compiling directly from v8 engine.
Stitching it all together:
V8 provides the functionalities related to running JS files, but to use system resources like Network, Files, etc., libuv is used. Also it provides a threading model for accessing the resources mentioned.
Additional reads:
Like to tinker and learn through trials and errors? We might use your quirky mind in our team! Join us in making the next life-centric digital solutions!