How NodeJs and V8 work together

Manish Sharma
2 min readDec 1, 2020

I don’t wanna beat around the bush.So come to the point.

Nodejs is runtime environment that execute the your javascript code I know you already have heard this definiton of node but now understand deeply what it acutally means,so when we write our javscript code, most of the time we use modules that is provided by npm library for example writing a code that require crypto library. Before executing our code using module, First understand that your code inside your file index.js is not 100% javascript code. because when you use a module(ex- http,path,fs etc..) these module are written in c++ language and there is an interlinkage between your js code and C++ code written for your module.

Now, you might be wondering why we need V8engine and Libuv.We know that all programming languages need to be compiled to get execute, and javascript is no different from others for it to be compiled and executed it use V8 and libuv .First thing is that your javascript is not just a javascript code when you use module, these module internally use some function which are implemented in c++ .In node repository there is a folder named lib where all the depedent function for you module(crypto module in our case) is defined in javascript language but its true and c++ implementation is define inside the src folder which is also inside the node repository. src folder where c++ code is written for module function have also some javascript keywords and that need to be converted to c++ and to do that there come the role of V8 whcih convert the these keyword in c++ equivalent code for to use.Now you also thinking how javascript code(in lib folder) and C++ code(in src folder) get connected.

This is connected by process.binding(‘your_module_name’)(in our case

process.binding(crypto); 

Hope this helps.

--

--