process.nextTick()
A Node.js function that queues a callback to run as soon as the current operation finishes, before promise callbacks and before the event loop continues.
In more detail
The nextTick queue is drained completely before the promise microtask queue. Recursive nextTick calls therefore starve the event loop, and the old process.maxTickDepth safeguard no longer exists. Prefer queueMicrotask() or setImmediate() unless you really need this ordering.
Related terms
- microtask — A small job, such as a promise callback, that runs as soon as the current piece of JavaScript finishes, before the event loop handles anything else.
- setImmediate() — A Node.js function that runs a callback in the check phase of the current event loop turn, right after I/O has been processed.
- event loop starvation — When the event loop can never move on because code keeps scheduling more immediate work, so timers and I/O are never handled.
Taught in
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Microtask Queues: process.nextTick vs Promise Timing — Node.js Internals & Backend Services