node:timers

Node.js timers module, resolvable via both ESM import and CommonJS require. It re-exports the runtime's timer globals as named bindings.
ExportDescription
setTimeout / clearTimeoutSchedule / cancel a one-shot callback.
setInterval / clearIntervalSchedule / cancel a repeating callback.
setImmediate / clearImmediateSchedule / cancel a callback for the next loop iteration.
These are the same functions installed as globals (see Timers). The legacy active() / unenroll() helpers are intentionally omitted.

node:timers/promises

The node:timers/promises submodule provides Promise-based timers.
ExportDescription
setTimeout(delay?, value?, options?)Resolves with value after delay ms; honours options.signal (AbortSignal).
setImmediate(value?, options?)Resolves with value on the next loop iteration; honours options.signal.
setInterval(delay?, value?, options?)Returns an async iterator that yields once per interval.
schedulerscheduler.wait(delay, options?) and scheduler.yield().
javascript
import { setTimeout as sleep } from "node:timers/promises";
await sleep(100);

See also

  • Node.js upstream: