Node.js Event Loop
A first-principles course on the Node.js event loop โ from why a single thread needs it, through the phases, queues, timers, microtasks, libuv and the thread pool, all the way to a single master mental model for predicting any program's output.
Module 01 โ Foundations
Why JavaScript's single thread makes blocking fatal and how non-blocking APIs offload the wait โ the motivation behind the event loop.
Module 03 โ Node.js Architecture
The pieces that make up Node.js โ V8, core bindings, libuv, and the OS โ and the boundary between single-threaded JS and native land.
Module 04 โ The Event Loop from First Principles
The event loop is just a C while-loop that runs ready callbacks โ trace one async operation from JavaScript call to callback.
Module 05 โ Event Loop Phases
The six phases, the four libuv queues, the two microtask queues, and the exact priority order that governs async execution.
Module 06 โ Timers
What setTimeout(fn, 0) really means โ timers as a minimum-delay promise, the min-heap, clamping to 1 ms, and why callbacks fire late.
Module 07 โ The Poll Phase
The poll phase โ where I/O callbacks run and the only phase that can sleep, deciding whether to wait for the OS or move on.
Module 08 โ setImmediate and the Check Phase
How setImmediate and the check phase work, why it differs from setTimeout(fn, 0), and the ordering inside I/O callbacks.
Module 09 โ Microtasks
The microtask VIP lane โ nextTick, Promises, and queueMicrotask, their priority order, and how a recursive nextTick can freeze the loop.
Module 11 โ Promises and async-await
How async/await desugars into Promises and microtasks โ code before the first await runs synchronously, the rest as a microtask.
Module 12 โ Complete Execution Traces
Eight verified Node programs traced step by step โ call stack, every queue, and the active phase โ from basics to async/await and I/O.
Module 14 โ libuv Deep Dive
How libuv gives Node a cross-platform event loop, thread pool, and async I/O โ and how handles vs requests keep the loop alive.
Module 15 โ The Thread Pool
Which Node operations borrow libuv's worker threads, why 'single-threaded' is only half true, and how the default pool size of 4 shows up.
Module 16 โ Event Loop Starvation
How one long or looping callback freezes the entire event loop, and how to chunk work with setImmediate to stay responsive.
Module 17 โ Node.js Concurrency Model
Event loop vs thread pool vs Worker Threads vs Cluster โ Node's four concurrency mechanisms and when to reach for each.
Module 18 โ Production Engineering
How event-loop behavior shapes real server latency, plus the Node tools to measure loop delay and utilization in production.
Module 20 โ The Master Mental Model
A single-page master model of the event loop โ phases, queue priorities, the thread pool, and the rules to predict any output.