- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
Node.js - V8 Module
The chrome V8 engine is a high-performance JavaScript engine that is written in C++ and used in Google Chrome. The computer can only understand the machine language but not JavaScript or HTML objects.
The code written in JavaScript is understood only by the browsers but not by the machines. So, the JS V8 engine will convert/transform the JavaScript code into machine-understandable language so that it can be understood by the machine.
The NodeJS V8 module provides APIs that are specific to the version of V8 built into the Node.js binary.
Including the V8 module
To include the V8 module, add the below-given syntax at the beginning of your Node.js document.
const v8 = require('v8')
The V8 module provides us with methods to get the information about the heap memory using the NodeJS v8.getHeapStatistics() method and v8.getHeapSpaceStatistics() method. Let's look into them with suitable examples.
Printing statistics of the V8 heap
To print the statistics of the V8 heap, we use the NodeJS v8.getHeapStatistics() method.
Example
const v8 = require('v8'); console.log(v8.getHeapStatistics());
Output
{ total_heap_size: 5369856, total_heap_size_executable: 524288, total_physical_size: 4303400, total_available_size: 17226376544, used_heap_size: 2849672, heap_size_limit: 17230200832, malloced_memory: 8192, peak_malloced_memory: 418904, does_zap_garbage: 0, number_of_native_contexts: 1, number_of_detached_contexts: 0 }
Printing statistics of the V8 heap space
To get the statistics of the V8 heap space, we use the NodeJS v8.getHeapSpaceStatistics() method.
Example
const v8 = require('v8'); console.log(v8.getHeapSpaceStatistics());
Output
[ { space_name: 'read_only_space', space_size: 262144, space_used_size: 32808, space_available_size: 0, physical_space_size: 33088 }, { space_name: 'new_space', space_size: 2097152, space_used_size: 649416, space_available_size: 398040, physical_space_size: 2088040 }, { space_name: 'old_space', space_size: 1916928, space_used_size: 1582320, space_available_size: 88312, physical_space_size: 1584560 }, { space_name: 'code_space', space_size: 430080, space_used_size: 155616, space_available_size: 0, physical_space_size: 172000 }, { space_name: 'map_space', space_size: 528384, space_used_size: 308880, space_available_size: 0, physical_space_size: 309720 }, { space_name: 'large_object_space', space_size: 135168, space_used_size: 131112, space_available_size: 0, physical_space_size: 135168 }, { space_name: 'code_large_object_space', space_size: 0, space_used_size: 0, space_available_size: 0, physical_space_size: 0 }, { space_name: 'new_large_object_space', space_size: 0, space_used_size: 0, space_available_size: 1047456, physical_space_size: 0 } ]
V8 Module Methods
Following is a list of methods available in the V8 module −
Sr.No | Module & Description |
---|---|
1 |
Used to retrieve an integer value that will represent the version tag of the v8 version, command-line flags, and the detected CPU features. |
2 |
Used to retrieve the statistics of the v8 heap space. |
3 |
Used to retrieve the statistics about the heap that is derived from the v8 version |
Serialization API Methods
Following is a list of methods available in the Serialization API −
Sr.No | Module & Description |
---|---|
1 |
Used to serialize any data type into a buffer |
2 |
Used to deserialize the buffer value into a JavaScript value. |
Serializer Methods
Following is a list of methods available in the v8.Serializer class −
Sr.No | Module & Description |
---|---|
1 |
Used for writing the header to the internal buffer. |
2 |
Used to serialize a JavaScript value and adds the serialized representation to the internal buffer |
3 |
Used for retrieving the value stored in the internal buffer. |
4 |
Used to write a raw 32-bit unsigned integer to the internal buffer. |
5 |
Used to write a raw 64-bit unsigned integer to the internal buffer. |
6 |
Used to write a JavaScript number value to the internal buffer. |
7 |
Used to write raw bytes into the serializer's internal buffer. |
Deserializer Methods
Following is a list of methods available in the v8.Deserializer class −
Sr.No | Module & Description |
---|---|
1 |
Used to read and validate the header in the internal buffer. |
2 |
Used for deserializing the JavaScript value that is written in the internal buffer. |
3 |
Used to read a raw 32-bit unsigned integer and return it. |
4 |
Used to read a raw 64-bit unsigned integer and return it as an array with its higher and lower values. |
5 |
Used to read raw bytes from the deserializer's internal buffer. |