process.nextTick()
Schedules a callback to run before the next event loop phase.
Syntax
process.nextTick(callback[, ...args]) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
callback | function | Yes | The function to invoke after the current operation completes. |
args | ...any | No | Arguments passed to the callback. |
Returns
void — Returns nothing.
Examples
console.log('start');
process.nextTick(() => console.log('tick'));
console.log('end');
Output
start
end
tick
function lazy(cb) {
process.nextTick(cb, null, 42);
}
lazy((err, v) => console.log(v));
Output
42
Notes
The nextTick queue drains completely before any Promise microtasks
and before timers or I/O. Recursive `nextTick` calls can starve the
event loop; prefer `queueMicrotask` or `setImmediate` unless you
specifically need this ordering.