v8 engine in Node.js

In this article I will cover about V8 engine and how Node.js is related to it

v8 engine in Node.js

Firstly what's Javascript engine, Js engine converts the javascript code that developers write in machine understandable instructions that allows computer to perform specific task. Js engines are mostly developed by web browser vendors.

What's v8 engine

  • V8 JavaScript engine is an open source JavaScript and WebAssembly engine that compiles JavaScript to optimized machine code before execution.
  • V8 JavaScript engine was initially developed for Google Chrome and Chromium web browsers to improve the performance of JavaScript execution.
  • To achieve faster JavaScript execution speeds, V8 translates JS code to more efficient machine code instead of using an interpreter
  • Nowadays, it is used in many projects such as NodeJS and MongoDB.

What's Node.js

Node.js is referred to as a runtime environment since it contains everything you need to run a JavaScript program and gives javascript the power to run at the server-side.. This V8 engine is at the heart of Node.js

How V8 JavaScript Engine Works

When a developer runs a JS script on V8, the following steps are taken by the engine:

  • The engine compiles and executes the JS code
  • The engine handles the call stack
  • The engine manages the memory heap
  • The engine handles the garbage collection
  • The engine provides all the data types, objects and functions
  • The engine also provides the event loop (sometimes implemented by the browser as well)

Relationship between Node.js and V8 engine

  • V8 is only a Javascript engine. It has no ability to communicate with the outside world. No netwokring, no file system, no security features, etc... So, nodejs adds a large runtime library that makes V8 useful for real world problems.

  • V8 has some memory limitations as per the system. Like on 32-bit it has of 512mb. And 1gb on 64-bit.We can increase upto 1gb for 32-bit and 1.7 for 64-bit.

  • The current binary of nodejs does not work without v8.

Other JS engines

Other browsers have their own JavaScript engine:

  • Firefox has SpiderMonkey
  • Safari has JavaScriptCore (also called Nitro)
  • Edge was originally based on Chakra but has more recently been rebuilt using Chromium and the V8 engine.

References:

  • Stackpath
  • Stackoverflow

Thanks for reading ! Feedback are suggestions are highly welcomed.