- 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
NodeJS v8.getHeapSpaceStatistics() Method
The NodeJS v8.getHeapSpaceStatistics() Method returns the statistics of the v8 heap space. This method returns the statistics as an array of objects such as new space, old space, code space, map space, and large object space. Each object contains data about space name, space size, space used size, space available size, and physical space size.
Syntax
Following is the syntax of the NodeJS v8.getHeapSpaceStatistics() Method −
v8.getHeapSpaceStatistics()
Parameters
This method does not accept any parameters.
Return Value
This method returns an array of objects that contains statistics of v8 heap space.
The following are properties present in the returned array of objects −
space_name − This is a string that specifies the name of the heap space.
space_size − This is a number that specifies the size of the heap space
space_used_size − This is a number that specifies the used heap space size.
space_available_size − A number that specifies the available heap space size.
physical_space_size − A number that specifies the physical heap space size.
Example
In the following example, we are trying to get the statistics of the v8 heap space using NodeJS v8.getHeapSpaceStatistics() method.
const v8 = require('v8'); console.log(v8.getHeapSpaceStatistics());
Output
After executing the above program, the NodeJS getHeapSpaceStatistics() method returned an array of objects containing properties about v8 heap space.
Statistics of v8 heap space: [ { space_name: 'new_space', space_size: 2097152, space_used_size: 653080, space_available_size: 378088, physical_space_size: 2059736 }, { space_name: 'old_space', space_size: 2396160, space_used_size: 2295248, space_available_size: 168, physical_space_size: 2338768 }, { space_name: 'code_space', space_size: 1048576, space_used_size: 572736, space_available_size: 0, physical_space_size: 605504 }, { space_name: 'map_space', space_size: 544768, space_used_size: 288160, space_available_size: 0, physical_space_size: 305568 }, { space_name: 'large_object_space', space_size: 0, space_used_size: 0, space_available_size: 17206803968, physical_space_size: 0 } ]
Example
In the following example, we are trying to print the statistics about the heap space in a tabular form.
const v8 = require('v8'); let statistics = v8.getHeapSpaceStatistics(); var EmpArr = [] for (var i = 0; i < statistics.length; i++){ var element = statistics[i]; EmpArr.push({ "Space Name": element['space_name'], "Space Size": element['space_size'], "Used Space Size": element['space_used_size'], "Space Available": element['space_available_size'], "Physical Space Size":element['physical_space_size'] },); } console.table(EmpArr)
Output
┌─────────┬───────────────────────────┬────────────┬─────────────────┬─────────────────┬─────────────────────┐ │ (index) │ Space Name │ Space Size │ Used Space Size │ Space Available │ Physical Space Size │ ├─────────┼───────────────────────────┼────────────┼─────────────────┼─────────────────┼─────────────────────┤ │ 0 │ 'read_only_space' │ 262144 │ 32808 │ 0 │ 33088 │ │ 1 │ 'new_space' │ 2097152 │ 649048 │ 398408 │ 2088064 │ │ 2 │ 'old_space' │ 1916928 │ 1582912 │ 88736 │ 1585152 │ │ 3 │ 'code_space' │ 430080 │ 155616 │ 0 │ 172000 │ │ 4 │ 'map_space' │ 528384 │ 308800 │ 0 │ 309640 │ │ 5 │ 'large_object_space' │ 135168 │ 131112 │ 0 │ 135168 │ │ 6 │ 'code_large_object_space' │ 0 │ 0 │ 0 │ 0 │ │ 7 │ 'new_large_object_space' │ 0 │ 0 │ 1047456 │ 0 │ └─────────┴───────────────────────────┴────────────┴─────────────────┴─────────────────┴──────────────────────
Note − To get a better understanding, let's execute the above code locally.
After executing the above code, the getHeapSpaceStatistics() method returns an array of 5 objects such as new space, old space, code space, map space, and large object space.
To Continue Learning Please Login
Login with Google