Course contentsShow
← JavaScript
Lesson 1218 of 2,72327. The Event LoopFree lesson

Event Loop in Node vs Browser

Key differences in phases and timers between Node's libuv event loop and browser implementations.

Event Loop in Node vs Browser

You'll learn: How Node.js and browser event loops differ in their implementation and behavior, despite following the same core principle.

The Fundamental Difference

Both Node.js and browsers use an event loop to handle asynchronous operations, but they're built on different foundations. Browsers implement their own event loop as part of the JavaScript engine integration. Node.js uses libuv, a C library that provides a more sophisticated, multi-phase event loop designed for I/O-heavy server operations.

Phases in Node.js Event Loop

Node's event loop has explicit phases that execute in a specific order each tick:

  1. Timers (setTimeout, setInterval callbacks)
  2. Pending callbacks (I/O callbacks deferred from previous cycle)
  3. Poll (retrieve new I/O events)
  4. Check (setImmediate callbacks)
  5. Close callbacks (socket closures, etc.)

Between each phase, microtasks (Promises, queueMicrotask) run completely.

Browser Event Loop is Simpler

Browsers don't expose these phases explicitly. They have:

  • A task queue (macrotasks like setTimeout)
  • A microtask queue (Promises)
  • Rendering steps (layout, paint)

The browser cycles: run one task → drain all microtasks → potentially render → repeat.

Timer Behavior Differences

In Node, setTimeout and setImmediate have phase-dependent ordering. In browsers, only setTimeout exists (no setImmediate), and its timing is simpler—tasks just queue up without phases.

Key Takeaway: Node's event loop has multiple named phases optimized for server I/O, while the browser's is simpler with a focus on rendering and user interaction. Both drain microtasks between tasks, but Node does so between phases too.