Node.js: V8 JavaScript Engine - Day One

Node.js is the most popular and rising current technology. Node.js is an open source, real time communication, and cross-platform server side language provided by JavaScript on Google's v8 JavaScript Engine. Node.js is used to build I/O based asynchronous event driven applications. If you want to get a basic introduction of Node.js along with installation process, then follow these links.

I will prefer the Visual Studio as an IDE for Node.js, but you can also use another IDE, like Eclipse. Today, I will give you a basic introduction about the V8 JavaScript Engine.

What is V8 JavaScript Engine?

V8 JavaScript Engine is the heart of any Node.js application. V8 is Google's open source high-performance JavaScript engine, developed by The Chromium Project for Google Chrome web browser. V8 JavaScript engine used in many projects, such as MongoDB and Node.js that are used as a server side.

V8 JavaScript Engine
Image Source: Google

Before starting the code on Node.js, it is very important to get the basic introduction of V8 JavaScript Engine. Let’s read about V8 JavaScript Engine.

What is the use of V8 Engine in Node.js ?

We know that JavaScript is used to write the programs in Node.js. JavaScript is very high level language that can’t be understood by micro processors. Node.js is developed by V8 JavaScript Engine that is written in C++ language. So, we can see that Node.js is written in C++ language. So, hierarchy says that all the JavaScript code is executed by V8 JavaScript engine; that converts the code into Assembly code and this assembly code further converts it into machine code.
V8 Engine
Now, it is clear how Node.js applications are executed. Now, we move in more depth of JavaScript.

What is ECMASCRIPT SPECIFICATION ?

The ECMASCRIPT Specification is a standardized specification of a scripting language standardized by ECMA International in ECMA-262 and ISO/IEC 16262. All JavaScript engines require a standard that is defined by ECMASCRIPT. All browser makers, like Microsoft, Google etc., follow these standards for their JavaScript engine to define how JavaScript language will work on all engines.

If you want to read all the JavaScript language standards, then follow this link.

ECMASCRIPT

When you go through all the documentation, you will find what JavaScript expects from any browser or JavaScript engine. It also defines how JavaScript language should work and what kind of features it expects.

Till now, I explained that Node.js is built on Chrome’s V8 engine. Now, I will show you the proof of how Node.js uses the V8 Engine. As we know that Node.js is open source, the code of Node.js is freely available. Let’s download the Node.js code from Github.

Go to https://github.com/nodejs/node link and download the source code.

download

After downloading the Node.js project, now, extract the files and open the project in Visual Studio.

project

Now, go to “deps” folder (the dependency folder). This folder contains all projects that are built outside the Node.js and implemented into this project.

deps

In “deps” directory, you will find the “V8” directory which contains all the files required to implement the V8 Engine's functionality.

Now, go to “src” folder and open the “node.h” file. When you open this file, you will find these lines of code.

Another point to consider is that JavaScript is a wrapper outside the C++ code. It means all the codes written in JavaScript are converted in low level language, C++ here, and then that is converted into machine code and gets executed. Let’s verify this statement. First, go to “lib” folder and in “lib” folder, open the “timer.js” file.

In this file, you will get a line of code.

code

The above lines of code show that node.h uses the “V8.h” file that is Chrome V8 Engine file. The above code is a C++ code that verifies that the Node.js is written in C++ language.

code

In the above image, we can see that process.binding function takes “timer_wrap” as parameter. Here, “timer_wrap” is a C++ file that you can find in src folder.

folder

For more clarification about “process.binding", you can go through this image.

process.binding
Image Source: Google

I hope you like the article. From the next article, we will start working on the coding section. Thanks for reading the article.

Up Next
    Ebook Download
    View all
    Learn
    View all