Back to the Catalog
nodejs
javascript
async

The Node.js Event Loop: libuv Phases, Timers & nextTick

18 questions

Step through the server-side event loop, the one libuv runs — not the browser model. Walk the phase cycle (timers, pending callbacks, poll, check, close), then settle the classics: setImmediate vs setTimeout(0) vs process.nextTick, and exactly where microtasks drain between phases. Every ordering puzzle here was executed and verified on Node.js. Explanation-first feedback reveals the why after each answer.

Questions

  1. Not answered. Which component actually owns and runs the event loop in Node.js?
  2. Not answered. Each turn of the loop runs its user-observable phases in which order?
  3. Not answered. Which of these callbacks are executed during the timers phase?
  4. Not answered. What makes the poll phase different from every other phase?
  5. Not answered. setImmediate(fn) callbacks execute in which event-loop phase? (one word)
  6. Not answered. A TCP socket emits its 'close' event. Which phase fires that handler?
  7. Not answered. Where does process.nextTick sit in the libuv phase model?
  8. Not answered. In what order do these four lines log?
  9. Not answered. Between two phases, Node runs a "microtask checkpoint." Which callbacks drain there?
  10. Not answered. Inside a file-read callback, when does the code after await run?
  11. Not answered. Why can a recursive process.nextTick freeze an entire Node server?
  12. Not answered. At the top level of a module, what is the output order here?
  13. Not answered. Move the very same two calls inside an I/O callback. Now what?
  14. Not answered. You schedule setTimeout(fn, 10), then run a 60 ms synchronous loop. When does fn fire?
  15. Not answered. Node clamps any setTimeout delay below 1 up to a floor. So setTimeout(fn, 0) is treated as how many milliseconds? (number only)
  16. Not answered. A server warms up: it reads a config file, then schedules four things. What order logs?
  17. Not answered. This snippet proves microtasks drain between every phase. What is the order?
  18. Not answered. You must process a huge job in chunks without freezing incoming requests. Which call yields control between chunks?