Performance

PerformanceObserver.observe()

Subscribes an observer to selected performance entry types. Notifications arrive asynchronously. Disconnect after observation to avoid retaining unnecessary subscriptions. Tested on Node.js 22.16.0. Example output (one line per entry): ["observed"].

Formal Syntax & Structure

nodejs syntaxnodejs
observer.observe(options)

Parameters & Attributes

NameTypeDescription
optionsobjectentryTypes or type and optional buffering.

Return Value

undefined

Starts observation.

Working Example

Example Snippetnodejs
import { PerformanceObserver, performance } from 'node:perf_hooks';let observer;try {    const received = new Promise(resolve => { observer = new PerformanceObserver(list => resolve(list.getEntries().map(e => e.name))); observer.observe({ entryTypes: ['mark'] }); });    performance.mark('observed');    console.log((await received).join(','));}finally {    observer?.disconnect();    performance.clearMarks('observed');}
Node.js Reference