The event loop is the mechanism that lets single-threaded Node.js perform non-blocking I/O. It continuously processes a queue of callbacks: while your JavaScript runs on one thread, I/O operations are offloaded, and their callbacks are run by the loop when they complete.
The phases of the loop
Each iteration ("tick") moves through ordered phases, each with its own callback queue:
┌───────────────────────────┐
┌─>│ timers (setTimeout) │ ← expired timer callbacks
│ ├───────────────────────────┤
│ │ pending I/O callbacks │
│ ├───────────────────────────┤
│ │ poll (I/O events) │ ← retrieve new I/O; execute their callbacks
│ ├───────────────────────────┤
│ │ check (setImmediate) │
│ ├───────────────────────────┤
└──│ close callbacks │
└───────────────────────────┘
