Open In App

How Node.js V8 runtime is different from what we have on chrome console ?

Last Updated : 23 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

NodeJS is an open-source and cross-platform JavaScript runtime environment that helps to run JavaScript outside the browser. It can be used to build a wide variety of software including backend servers, scripts, command line tools, games, native apps, etc. NodeJS is single-threaded, we use it primarily for non-blocking, event-driven servers. It is built upon V8 which is a JavaScript engine made by Google. V8 is also used to run JavaScript inside the Google Chrome console.

Yes, both NodeJS and Chrome use the same V8 engine for executing JavaScript. However, there are some differences in the way they execute.

Overview of the V8 engine: V8 is a high-performance JavaScript engine written in C++ and developed by Google. It is used in Chrome and NodeJS. Basically, V8 converts JavaScript code into machine code which is executable by the computer.

V8 engine model:

V8 engine model

The image above shows how the source code is converted to machine code. This process is done in the following steps:

  1. The source code is passed into the engine. 
  2. The baseline compiler is responsible for converting the source code into an un-optimized bytecode (this way the bytecode is generated quickly and the program is initiated quickly).
  3. The bytecode produced in step 2 is now interpreted by the interpreter and converted to machine code which is executable by the machine.
  4. The TurboFan optimization compiler takes the bytecode and generates an optimized machine code in place of the un-optimized machine code. This helps to create efficient machine code which is fast. As time goes on, the bytecode is fully optimized by the TurboFan compiler and this process is done in the background without disturbing the baseline compiler and interpreter.

How NodeJS V8 runtime is different from the Chrome console?  

Apparently, both NodeJS and Chrome console uses the same V8 JavaScript engine behind the scene. NodeJS was created to make JavaScript executable on the local machine without the browser. Both of them follow the same execution process as described above. 

However, since both environments are different there are some differences in the JavaScript running in Chrome and NodeJS.

  1. System access: NodeJS runs in the machine so it has full access to the Operating system which means it can read, write data to files directly and perform many other actions. NodeJS can also be used to create a desktop application using a framework like electron.js. Chrome console has limited access to the system because it is running inside the browser. It cannot perform actions the same way Node can.
  2. Module system: In NodeJS everything is kept in modules and data is transferred between files using modules. However, for Chrome, this is not mandatory.
  3. Missing objects in both ecosystem: NodeJS do not have the document, window, or location objects because it has no window or DOM to work with. Similarly, Chrome also does not have access to the global object and modules like fs, path, and so on.
  4. GUI vs headless: Chrome has a GUI to operate it and NodeJS is headless.
     

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads