Timers

timers/promises.setTimeout()

Returns a promise fulfilled with the supplied value after a timer runs. An abort signal rejects the wait instead. This delays continuation without blocking the JavaScript thread; it does not guarantee precise wall-clock timing. Tested on Node.js 22.16.0. Example output (one line per entry): ["ready", "AbortError"].

Formal Syntax & Structure

nodejs syntaxnodejs
setTimeout([delay[, value[, options]]])

Parameters & Attributes

NameTypeDescription
delaynumberRequested milliseconds.
valueanyFulfillment value.
optionsobjectMay include signal and ref.

Return Value

Promise

Fulfills with value or rejects on cancellation.

Working Example

Example Snippetnodejs
import { setTimeout as wait } from 'node:timers/promises';console.log(await wait(1, 'ready'));const c = new AbortController();c.abort();try {    await wait(1000, null, { signal: c.signal });}catch (e) {    console.log(e.name);}
Node.js Reference