Skip to content

Glossary: Node.js Basics

setInterval / setTimeout (timers)

Also written: setInterval, clearInterval, setTimeout, sleep

`setTimeout(fn, ms)` runs `fn` once after a delay, and `setInterval(fn, ms)` runs it every `ms` milliseconds until `clearInterval` stops it. `setTimeout` from `node:timers/promises` is a promise version, used here as `sleep`.

Where the book teaches it

Related terms

Blocking the event loopEvent loop