V8#

The node:v8 module exposes APIs that are specific to the version of V8 built into the Node.js binary. It can be accessed using:

import v8 from 'node:v8';
const v8 = require('node:v8');
javascript

v8.cachedDataVersionTag()#

Returns an integer representing a version tag derived from the V8 version, command-line flags, and detected CPU features. This is useful for determining whether a vm.Script cachedData buffer is compatible with this instance of V8.

console.log(v8.cachedDataVersionTag()); // 3947234607
// The value returned by v8.cachedDataVersionTag() is derived from the V8
// version, command-line flags, and detected CPU features. Test that the value
// does indeed update when flags are toggled.
v8.setFlagsFromString('--allow_natives_syntax');
console.log(v8.cachedDataVersionTag()); // 183726201
js

v8.getHeapCodeStatistics()#

Get statistics about code and its metadata in the heap, see V8 GetHeapCodeAndMetadataStatistics API. Returns an object with the following properties:

{
  "code_and_metadata_size": 212208,
  "bytecode_and_metadata_size": 161368,
  "external_script_source_size": 1410794,
  "cpu_profiler_metadata_size": 0
}
json

v8.getHeapSnapshot([options])#