Node.js Event Loop Interview Questions With Answers
The event loop comes up in every Node.js interview. Here are the common questions and how to answer them.
Node.js Event Loop Interview Questions With Answers
The event loop comes up in every Node.js interview. Here are the common questions and how to answer them.
What is the event loop in Node.js?
A single-threaded loop that processes callbacks from completed async operations through phases (timers, pending, poll, check, close). It makes Node.js non-blocking by handling I/O asynchronously through libuv while processing one callback at a time.
What are the event loop phases?
Timers (setTimeout), pending callbacks (deferred I/O), idle/prepare (internal), poll (new I/O events), check (setImmediate), and close callbacks. Each processes specific callback types in order.
What is the difference between setTimeout and setImmediate?
setTimeout runs in the timers phase after a delay. setImmediate runs in the check phase right after poll. On the next tick, setImmediate usually runs before setTimeout(0) when there are no pending timers.
What is process.nextTick?
A Node.js-specific function that schedules a callback to run before the next event loop phase, even before promise microtasks. It is the most urgent scheduling mechanism but can starve the loop if overused.
What are microtasks and macrotasks?
Microtasks are process.nextTick and promise callbacks, which run after the current operation and before the next macrotask. Macrotasks are setTimeout, setImmediate, and I/O callbacks, which run one per event loop phase.
How to Answer Well
Explain the phases, the order, and why it matters. Connect the event loop to Node.js's single-threaded concurrency model, and show you understand why blocking the loop is the biggest performance concern.
The Takeaway
Know the event loop, its phases, setTimeout vs setImmediate, process.nextTick, and microtasks vs macrotasks. Connect these to Node.js's concurrency model and the importance of keeping the loop non-blocking.
A single-threaded loop that processes callbacks from completed async operations through phases: timers, pending, poll, check, close. It makes Node.js non-blocking by handling I/O asynchronously through libuv while processing one callback at a time.
Timers (setTimeout), pending callbacks (deferred I/O), idle/prepare (internal), poll (new I/O events), check (setImmediate), and close callbacks. Each processes specific callback types in order through each tick of the loop.
setTimeout runs in the timers phase after a delay. setImmediate runs in the check phase right after poll. On the next tick, setImmediate usually runs before setTimeout(0) when there are no pending timers.
A Node.js-specific function that schedules a callback to run before the next event loop phase, even before promise microtasks. It is the most urgent scheduling mechanism but can starve the loop if overused, so use it sparingly.
Microtasks are process.nextTick and promise callbacks, which run after the current operation and before the next macrotask. Macrotasks are setTimeout, setImmediate, and I/O callbacks, which run one per event loop phase.
Ready to master Node.js completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master Node.js
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

