Skip to content
Cloudflare Docs

timers

To enable built-in Node.js APIs and polyfills, add the nodejs_compat compatibility flag to your Wrangler configuration file. This also enables nodejs_compat_v2 as long as your compatibility date is 2024-09-23 or later. Learn more about the Node.js compatibility flag and v2.

Use node:timers APIs to schedule functions to be executed later.

This includes setTimeout for calling a function after a delay, setInterval for calling a function repeatedly, and setImmediate for calling a function in the next iteration of the event loop.

index.js
import timers from "node:timers";
console.log("first");
timers.setTimeout(() => {
console.log("last");
}, 10);
timers.setTimeout(() => {
console.log("next");
});

The full node:timers API is documented in the Node.js documentation for node:timers.