Skip to content

node:v8

How Elide supports Node's v8 module: six exports, including heap statistics and a JSON-based serialize that is not V8's structured-clone format.

On this page

node:v8 exports six members of Node’s v8.

Example

js
// v8.mjs
import v8 from "node:v8";

const bytes = v8.serialize({ id: 7, tags: ["a"] });
console.log(JSON.stringify(v8.deserialize(bytes)));
const heap = v8.getHeapStatistics();
console.log(heap.used_heap_size > 0, heap.total_heap_size >= heap.used_heap_size);
console.log(typeof v8.cachedDataVersionTag());
utf-8 · js · Lines: 8

elide run v8.mjs prints:

text
{"id":7,"tags":["a"]}
true true
number
utf-8 · text · Lines: 3

Differences from Node

Only these members are exported:

OperationBehavior
cachedDataVersionTag()Returns a stable 32-bit tag for the running binary.
getHeapStatistics()Returns a heap-statistics object in Node’s format.
getHeapSpaceStatistics()Returns one entry per memory pool, with names such as eden space.
setFlagsFromString(flags)Accepts a string and has no effect.
serialize(value)Encodes JSON.stringify(value) as UTF-8 in a Uint8Array.
deserialize(buffer)Decodes UTF-8 and parses the JSON.

serialize output is not V8’s structured-clone format; circular objects throw TypeError.

Reference

Status: Partial · Not measured · since 1.1.0

Exports

ExportKindStatusNotes
getHeapStatistics()functionFullReturns an object with V8 heap statistics
getHeapSpaceStatistics()functionFullReturns statistics about V8 heap spaces
setFlagsFromString()functionFullSet additional V8 command-line flags
serialize()functionFullSerializes a value into a buffer
deserialize()functionFullReads a value written by serialize() from a buffer

Not implemented

DefaultDeserializer, DefaultSerializer, Deserializer, GCProfiler, Serializer, getCppHeapStatistics, getHeapCodeStatistics, getHeapSnapshot, isStringOneByteRepresentation, promiseHooks, queryObjects, setHeapSnapshotNearHeapLimit, startCpuProfile, startHeapProfile, startupSnapshot, stopCoverage, takeCoverage, writeHeapSnapshot.

Was this page helpful?