Node.js Event Loop
Principles and uses
After synchronous code, process ready work in the defined order.
Use Async ordering and delays
Schedule four operations inside an I/O callback. Scheduling does not execute them immediately; current synchronous code finishes first.
↔ Drag to explore
fs.readFile('data.txt', () => { /* schedule callbacks */ });Learn more
The example schedules nextTick, Promise, setImmediate, and setTimeout(0) inside a CommonJS I/O callback on Node.js 20+. Under these conditions the order is nextTick, Promise, immediate, timer; do not generalize the top-level immediate/timer order. Timers run after poll since the libuv change in Node 20. Long synchronous work delays other callbacks.