What is the order of setTimeout, setImmediate, and process.nextTick?
process.nextTick fires first (immediately after current operation), then Promise.then (microtask), then setTimeout and setImmediate (order varies in the same context, but setImmediate always fires after I/O in an I/O callback).
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Node.js Event Loop Interview Questions Common Questions and Answers
The event loop allows Node.js to perform non-blocking I/O despite being single-threaded. It offloads I/O to the system kernel and processes results via callbacks. It has phases: timers (setTimeout/setInterval), poll (I/O events), check (setImmediate), and close. Microtasks (nextTick, Promises) run between phases.
Node.js uses a single thread for JavaScript execution (V8) to avoid context switching and thread synchronization complexity. It uses libuv's thread pool (4 threads by default) for I/O operations and non-blocking I/O to handle thousands of concurrent connections efficiently.
process.nextTick fires immediately after the current operation, before I/O events (can starve I/O if overused). setImmediate fires in the next event loop iteration, after I/O events (safe for recursive calls). nextTick always fires before setImmediate.
Still have questions?
Browse all our FAQs or reach out to our support team
