NODEJS Contents

Microtasks vs Macrotasks (Promises vs Timers)

Learn how microtasks like Promises and process.nextTick are prioritized in the Node.js event loop.

On this page

Microtask Queue

Microtasks run immediately after the current call stack completes, before the event loop proceeds to the next phase.

Promise Example

Promise.resolve().then(() => console.log('microtask'));
setTimeout(() => console.log('timeout'), 0);

Order

The promise callback runs before the timeout callback.

process.nextTick

process.nextTick runs even before other microtasks and should be used carefully to avoid starvation.

Production Insight

Overusing microtasks can delay I/O callbacks and reduce responsiveness.