Skip to main content
v8 - Node documentation

Usage in Deno

import * as mod from "node:v8";
Deno compatibility

cachedDataVersionTag and getHeapStatistics are supported. setFlagsFromStrings is a noop. Other APIs are not supported and will throw and error.

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:

const v8 = require('node:v8');

Classes

c
DefaultDeserializer

A subclass of Deserializer corresponding to the format written by DefaultSerializer.

c
DefaultSerializer

A subclass of Serializer that serializes TypedArray(in particular Buffer) and DataView objects as host objects, and onlystores the part of their underlying ArrayBuffers that they are referring to.

c
Deserializer
No documentation available
c
GCProfiler

This API collects GC data in current thread.

c
Serializer
No documentation available

Functions

f
cachedDataVersionTag

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

f
deserialize

Uses a DefaultDeserializer with default options to read a JS valuefrom a buffer.

f
getHeapCodeStatistics

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

f
getHeapSnapshot

Generates a snapshot of the current V8 heap and returns a ReadableStream that may be used to read the JSON serialized representation.This JSON stream format is intended to be used with tools such asChrome DevTools. The JSON schema is undocumented and specific to theV8 engine. Therefore, the schema may change from one version of V8 to the next.

f
getHeapSpaceStatistics

Returns statistics about the V8 heap spaces, i.e. the segments which make upthe V8 heap. Neither the ordering of heap spaces, nor the availability of aheap space can be guaranteed as the statistics are provided via theV8 GetHeapSpaceStatistics function and may change from one V8 version to thenext.

f
getHeapStatistics

Returns an object with the following properties:

f
serialize

Uses a DefaultSerializer to serialize value into a buffer.

f
setFlagsFromString

The v8.setFlagsFromString() method can be used to programmatically setV8 command-line flags. This method should be used with care. Changing settingsafter the VM has started may result in unpredictable behavior, includingcrashes and data loss; or it may simply do nothing.

f
setHeapSnapshotNearHeapLimit

The API is a no-op if --heapsnapshot-near-heap-limit is already set from the command line or the API is called more than once.limit must be a positive integer. See --heapsnapshot-near-heap-limit for more information.

f
stopCoverage

The v8.stopCoverage() method allows the user to stop the coverage collectionstarted by NODE_V8_COVERAGE, so that V8 can release the execution countrecords and optimize code. This can be used in conjunction with takeCoverage if the user wants to collect the coverage on demand.

f
takeCoverage

The v8.takeCoverage() method allows the user to write the coverage started by NODE_V8_COVERAGE to disk on demand. This method can be invoked multipletimes during the lifetime of the process. Each time the execution counter willbe reset and a new coverage report will be written to the directory specifiedby NODE_V8_COVERAGE.

f
writeHeapSnapshot

Generates a snapshot of the current V8 heap and writes it to a JSONfile. This file is intended to be used with tools such as ChromeDevTools. The JSON schema is undocumented and specific to the V8engine, and may change from one version of V8 to the next.

Interfaces

I
After

Called immediately after a promise continuation executes. This may be after a then(), catch(), or finally() handler or before an await after another await.

I
Before

Called before a promise continuation executes. This can be in the form of then(), catch(), or finally() handlers or an await resuming.

I
GCProfilerResult
No documentation available
I
HeapCodeStatistics
No documentation available
I
HeapInfo
No documentation available
I
HeapSnapshotOptions
No documentation available
I
HeapSpaceInfo
No documentation available
I
HeapSpaceStatistics
No documentation available
I
HeapStatistics
No documentation available
I
HookCallbacks

Key events in the lifetime of a promise have been categorized into four areas: creation of a promise, before/after a continuation handler is called oraround an await, and when the promise resolves or rejects.

I
Init

Called when a promise is constructed. This does not mean that corresponding before/after events will occur, only that the possibility exists. This willhappen if a promise is created without ever getting a continuation.

I
PromiseHooks
No documentation available
I
Settled

Called when the promise receives a resolution or rejection value. This may occur synchronously in the case of Promise.resolve() orPromise.reject().

I
StartupSnapshot
No documentation available

Type Aliases

T
DoesZapCodeSpaceFlag
No documentation available
T
StartupSnapshotCallbackFn
No documentation available

Variables

v
promiseHooks

The promiseHooks interface can be used to track promise lifecycle events.

v
startupSnapshot

The v8.startupSnapshot interface can be used to add serialization and deserialization hooks for custom startup snapshots.