NodeJS Architecture: Relationship between libUV, V8 and JS

Jeevan D C
DKatalis
Published in
2 min readFeb 10, 2021

Components ownership:

libUV:

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 :-

  1. Compiles and executes JS code
  2. Handling call stack
  3. Managing memory allocation for objects
  4. Garbage collection — of objects which are no longer in use
  5. Provide all the data types, operators, objects and functions

node.js:

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

https://github.com/nodejs/node

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.

save as app.js
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!

--

--