Skip to content
Learn Netverks

Lesson

Step 15/36 42% through track

timers-scheduling

Timers and scheduling

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Timers and scheduling: the syntax, APIs, and habits you need before advancing in Node.js.

Teams ship Timers and scheduling on every Node.js codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Timers and scheduling in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons.

When you can explain the previous lesson's ideas without copying starter code.

Node schedules work with setTimeout, setInterval, and setImmediate. Timers are macrotasks—they run after current sync code and microtasks complete.

Common APIs

  • setTimeout(fn, ms) — run once after delay (minimum delay not guaranteed under load)
  • setInterval(fn, ms) — repeat until clearInterval
  • setImmediate(fn) — run after I/O callbacks in the check phase

Promisified sleep

await new Promise(r => setTimeout(r, 1000));

Use sparingly in tests or retries—not for throttling production traffic (use proper rate limiters).

Important interview questions and answers

  1. Q: setImmediate vs setTimeout(0)?
    A: Order differs by context; both schedule macrotasks—prefer one style consistently in codebases.
  2. Q: clearTimeout?
    A: Cancels a scheduled timer—store the returned id when debouncing user input.

Self-check

  1. Are timers microtasks or macrotasks?
  2. Why not use busy-wait loops for delays?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • setImmediate vs setTimeout?
  • clearInterval when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump