What is process.nextTick() in Node.js?

Why Interviewers Ask This

This is a classic screening question for Node.js roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

process.nextTick(callback) adds the callback to the nextTick queue, which is processed immediately after the current operation completes — before the event loop moves to the next phase, before any I/O, timers, or setImmediate callbacks. It is the highest-priority async scheduling mechanism. Use cases: (1) Allow a function to complete before a caller's callback runs; (2) Allow an EventEmitter's "error" event to be caught after the emitter is set up (avoid emitting events before listeners are attached); (3) Allow cleanup code to run before more I/O is processed. Warning: overusing process.nextTick() can starve the event loop — if nextTick callbacks keep adding more nextTick callbacks, I/O events are never processed (use setImmediate() to yield to I/O). The distinction: nextTick fires before the next event loop iteration; setImmediate fires in the next iteration's check phase.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last Node.js project, I used this when...' immediately makes your answer more credible and memorable.