Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

Event Loop: How Browsers and Node.js Differ

Browsers coordinate tasks and microtasks with rendering; Node.js has its own event loop, next-tick queue, and process-liveness rules for timers.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Browsers and Node.js both run JavaScript synchronously to completion, then schedule asynchronous work through host-managed queues. The key difference is what each host coordinates: browsers integrate task and microtask scheduling with rendering, while Node.js has its own event loop, a separate process.nextTick() queue, and timers whose handles can keep the process alive.

What the event loop does in both environments

JavaScript code on a given execution thread runs one operation at a time. When the current stack of synchronous work finishes, the host can run eligible callbacks. That shared model is useful, but it does not mean browsers and Node.js use identical queues or scheduling rules.

In a browser, an event-loop iteration selects a runnable task. Tasks can include starting a script, dispatching an event, or running a timer callback. After the task finishes and the execution stack is empty, the browser drains the microtask queue. Node.js has its own event-loop implementation and additional scheduling behavior, so the browser’s task-and-microtask description is not a complete model for Node.

How browser tasks, microtasks, and rendering interact

After a browser task completes, microtasks run until the queue is empty. Promise reactions and MutationObserver callbacks use the microtask queue. If a microtask queues another microtask, that new callback is also eligible during the same drain. The browser may update rendering after the microtask checkpoint, before moving on to another task. MDN explains browser microtasks and their draining behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This means a microtask is not a way to yield to the browser’s input handling or rendering. A chain that continually adds more microtasks can keep the queue from emptying, delaying later tasks and browser work. Likewise, long-running JavaScript on the main thread can make the interface unresponsive. Keep microtasks short and avoid recursively replenishing the queue.

Use requestAnimationFrame for frame-bound updates

requestAnimationFrame() asks the browser to call a function before the next repaint. It is one-shot: an animation that needs another frame must request one again, usually from its callback. Most browsers pause these callbacks in background tabs or hidden iframes, so this API is for visual updates tied to repainting, not a general-purpose timer. MDN documents its repaint timing, one-shot behavior, and timestamp.

Use the callback’s timestamp to calculate animation progress rather than assuming that every frame has a fixed duration; display refresh rates vary. For computational work that would otherwise occupy a window’s main thread, a Web Worker can run scripts on a separate thread. DOM updates still belong to the relevant window context. Browser event-loop details can vary across windows and contexts, so do not assume every tab in every browser shares one event loop. MDN’s JavaScript runtime guide covers browser agents, rendering, and workers.

How Node.js scheduling differs

Node.js timer functions have familiar names, but they are built around Node’s event-loop implementation rather than the browser’s scheduling model. A timer delay is a threshold for when a callback becomes eligible, not a promise of exact wall-clock execution: other work already occupying the loop can delay it. The Node.js v26.10.0 Timers documentation describes these scheduling behaviors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

setImmediate and timers

setImmediate() schedules a callback to run after I/O callbacks. Multiple immediates run in the order they were created; an immediate scheduled from within an immediate callback waits for a subsequent event-loop iteration. Do not treat setImmediate() as a portable browser API, or assume a universal ordering between it and a zero-delay timer when the scheduling context can affect the result.

Node timer and immediate handles are referenced by default, so active ones normally keep the process running. Calling .unref() on a handle means that handle alone will not require Node to stay alive; if no other activity remains, the process may exit before its callback runs.

process.nextTick and microtasks

process.nextTick() is not just another name for a Promise callback. Node drains its next-tick queue after the current JavaScript stack operation and before continuing through the event loop; after that queue drains, it drains the microtask queue. The relative order with queueMicrotask() depends on module context: in CommonJS, next-tick callbacks run first, while in ES modules the documented order is reversed because module evaluation itself occurs within the microtask queue. Node.js v26.10.0 documents next-tick scheduling and this CommonJS/ES-module distinction.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Reading a scheduling example without assuming a universal output

This example is intended to show which kinds of work are scheduled, not to promise one console order across all contexts:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
console.log("sync");

Promise.resolve().then(() => console.log("promise"));
queueMicrotask(() => console.log("microtask"));
process.nextTick(() => console.log("nextTick"));

setTimeout(() => console.log("timeout"), 0);
setImmediate(() => console.log("immediate"));

The synchronous log runs as part of the current stack. In Node.js, the relative placement of nextTick and the Promise or queueMicrotask() callbacks depends on whether this code is evaluated as CommonJS or as an ES module. The timer’s zero delay does not mean “run immediately,” and this example does not establish a universal timer-versus-immediate order. For the same reason, do not use one observed console trace as a cross-context scheduling guarantee.

Practical rules for choosing the right mechanism

  • For short follow-up work in a browser: use a microtask when it needs to run after the current stack but before the next task; do not use a chain of microtasks to yield to input or rendering.
  • For visual animation: use requestAnimationFrame() and compute progress from its timestamp.
  • For substantial browser computation: consider a Web Worker so the window’s main thread can remain responsive.
  • For Node.js ordering: distinguish process.nextTick() from Promise and queueMicrotask() callbacks, and account for whether the code runs as CommonJS or an ES module.
  • For Node.js timers: treat delays as scheduling thresholds, and use .unref() only when the handle should not by itself keep the process alive.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.