Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Node.js · Function

queueMicrotask

Queues a callback as a V8 microtask for asynchronous execution after the current code completes. Node processes process.nextTick() callbacks before this microtask queue within an event-loop turn.

Since
v11.0.0

How it works

queueMicrotask(callback) schedules the supplied function in V8's microtask queue. Node.js processes that queue after the current execution completes; within each event-loop turn, the process.nextTick() queue runs before it. A callback exception is reported through the process uncaughtException event.

Syntax

queueMicrotask(callback)

Parameters

NameTypeDescription
callbackFunctionFunction to be queued for invocation as a microtask.

Returns

void

Key points

  • Calling the function schedules the provided callback for microtask execution.
  • V8 owns the queue that stores and runs these microtasks.
  • The sole parameter is a function that Node will invoke later.
  • Node.js introduced this global API in version 11.0.0.

Common mistakes

  • An exception thrown by the callback is emitted through process's uncaughtException event rather than being returned.
  • Do not assume it outranks process.nextTick(); Node drains the next-tick queue first in each event-loop turn.

Example: Queue work after the current turn

queueMicrotask(() => {
  console.log('microtask');
});
console.log('synchronous');

The synchronous message prints first; the queued callback runs afterward in the microtask phase.

When to use it

Normalize synchronous and asynchronous paths

A cached result must still be delivered asynchronously so callers observe consistent timing.

Defer work within the current turn

Small follow-up work should run before timers and ordinary I/O callbacks.

Schedule a lightweight microtask

An API needs Promise-like microtask scheduling without creating a Promise.

Interview questions

QWhat does queueMicrotask() do?

It accepts one callback function and returns no value. The callback is placed on V8's microtask queue and invoked asynchronously after the current execution completes.

Follow-up: How does it compare with process.nextTick()? Node processes the next-tick queue before the microtask queue during each event-loop turn.

QWhen would you use queueMicrotask()?

The callback is executed as a microtask rather than as a timer or ordinary I/O callback. This makes it useful for deferring work while keeping it ahead of later event-loop phases.

Follow-up: How can a callback failure surface? A thrown exception causes the process uncaughtException event to be emitted.

QWhat are the function's parameter and return behavior?

Its parameter is callback, documented as a function to be queued. The function itself has no documented return value, so the API signature is queueMicrotask(callback) with a void result.

Follow-up: What runtime owns the queue? V8 manages the microtask queue, while Node.js manages the separate process.nextTick() queue.

  • process.nextTick()
  • Promise

Source: Global objects. Checked 2026-10-15.