NodeJS Architecture: Relationship between libUV, V8 and JS
Gives access to the operating system to perform tasks related to the filesystem or time scheduled tasks etc.
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
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.