C++ under Node.js

C++ under Node.js

·

2 min read

We’re going to look at the internals of Node.js with a very simple diagram.

Internally, Node.js comprises a set of dependencies crucial for executing your code. Among these dependencies, V8 and libuv stand out as two of the most significant ones.

  1. V8: is an open-source Javascript engine created by Google. It enables us to execute javascript code outside of the browser and that’s what we do when we run our javascript code from the terminal.

  2. libuv: is a C++ open-source project that gives Node.js access to the operating systems underlying file system. It gives us access to networking and it also handles some aspects of concurrency as well.

“Why we use Node.js again?”

important! : You might wonder why we don’t directly use V8 or libuv. Please look at the previous diagram and hope you get the idea.

  1. Node.js facilitates writing JavaScript code by bridging it with underlying C++ components for interpretation and execution. Notably, V8 consists of approximately 70 percent C++ code, while libuv is entirely composed of C++.

  2. Node.js provides a series of wrappers and a very unified inconsistent API for us to use inside of our projects.

In short, Node.js gives us a nice consistent API for getting access to functionality that is ultimately implemented inside a V8 in libuv and so we don’t need to worry about the C++code! :)

Recap

  • The Node source code is written in Javascript and C++

  • V8 is used to interpret and execute Javascript code, while libuv is used for accessing the filesystem and some aspects of concurrency.