Node.js versus browser scheduling
How it works
Node has event-loop phases for timers, polling and other host callbacks; it also provides process.nextTick and setImmediate. In a Node CommonJS top-level script, the next-tick queue is processed before the ordinary microtask queue at the relevant boundary. ES module evaluation can give a different order because it already runs in an asynchronous evaluation context. Do not generalize timer versus immediate ordering across all contexts or versions. Browsers use HTML event loops and have rendering opportunities rather than Node-specific phases.
Example 1
Save each file separately. Run with Node.js: main.cjs. This is a multi-file example, not a single editor snippet.
main.cjs
process.nextTick(()=>console.log("tick"));queueMicrotask(()=>console.log("micro"));console.log("sync");Expected output in the tested environment:
synctickmicroThis order is observed in a CommonJS top-level file.
Example 2
Save each file separately. Run with Node.js: main.mjs. This is a multi-file example, not a single editor snippet.
main.mjs
process.nextTick(()=>console.log("tick"));queueMicrotask(()=>console.log("micro"));console.log("sync");Expected output in the tested environment:
syncmicrotickThe ES module context produces a different observed order in this runtime.
Common mistake
process.nextTick is not a browser API or a portable synonym for queueMicrotask. Avoid using its priority for cross-host correctness.
Practice
Run the two files separately in Node and write the observed order and version. Replace nextTick with queueMicrotask and compare again.
Run this practice in the documented local environment. ByteMind module and asynchronous grader support is not yet verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Node.js versus browser scheduling — Knowledge Check
Reason about the concept and predict its behavior in the indicated environment.
Is process.nextTick part of the ECMAScript standard language?
Why is the CommonJS top-level ordering not sufficient to predict every ESM ordering?
Which is a portable teaching rule about timer versus immediate ordering?
For Node.js versus browser scheduling, what is the console output of example 1 in Node.js 22.16.0?
// File: main.cjsprocess.nextTick(()=>console.log("tick"));queueMicrotask(()=>console.log("micro"));console.log("sync");For Node.js versus browser scheduling, what is the console output of example 2 in Node.js 22.16.0?
// File: main.mjsprocess.nextTick(()=>console.log("tick"));queueMicrotask(()=>console.log("micro"));console.log("sync");