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

Node.js · Pipe

process.nextTick

process.nextTick() defers a callback until the current JavaScript operation finishes, then runs it before the event loop continues. It can also pass extra arguments to that callback.

How it works

Calling process.nextTick() places a callback in Node.js's next-tick queue. Node drains that queue after the current JavaScript stack or operation finishes and before continuing the event loop; optional arguments are supplied to the callback when it runs.

Syntax

process.nextTick(callback, ...args?): void

Parameters

NameTypeDescription
callbackFunctionFunction to place in the next-tick queue.
...argsanyOptional values passed to callback when it is invoked.

Returns

void

Key points

  • The API enqueues the supplied callback in Node's next-tick queue.
  • Node drains the queue after the current JavaScript operation finishes.
  • Callbacks run before the event loop advances to further phases.
  • Unlike queueMicrotask(), nextTick can pass additional arguments directly to the callback.
  • Node drains the microtask queue immediately after draining the next-tick queue.

Common mistakes

  • Recursively scheduling more next-tick callbacks can create an infinite loop.
  • In CommonJS, next-tick callbacks run before queueMicrotask callbacks; ordering differs in ES modules.
  • Prefer queueMicrotask() when nextTick-specific behavior, such as callback arguments, is unnecessary.

Example: Defer work until the current operation finishes

console.log('start');
process.nextTick((name) => {
  console.log(`next tick: ${name}`);
}, 'worker');
console.log('end');

The synchronous logs appear first; the callback runs after the current JavaScript operation completes.

When to use it

Defer callback execution

An API must invoke a callback asynchronously while allowing the current function to finish initializing state first.

Pre-event-loop follow-up

Error handling, cleanup, or retry logic must run before the event loop advances.

Pass callback arguments

A deferred callback needs values supplied without creating a closure.

Interview questions

QWhen does process.nextTick() run?

It schedules a callback in the next-tick queue. Node drains that queue after the current JavaScript operation completes and before the event loop continues.

Follow-up: How does it compare with setImmediate()? setImmediate() runs on a later event-loop iteration, while nextTick runs before the event loop proceeds.

QWhat is the purpose of the variadic arguments?

The callback is called with the additional values supplied after the callback argument. Its signature is process.nextTick(callback, ...args?).

Follow-up: How can queueMicrotask receive equivalent values? Capture them in a closure or use a bound function.

QWhat is the main event-loop risk?

Recursive scheduling can keep the next-tick queue from emptying and starve I/O. Use it sparingly and avoid unbounded chains.

Follow-up: What alternative is generally preferred when nextTick-specific capabilities are not needed? queueMicrotask().

  • queueMicrotask()
  • setImmediate()
  • setTimeout()
  • event loop

Source: process.nextTick | Node.js 26.11.1 Documentation. Checked 2026-10-15.