Async JavaScript and Event Loop Interview Questions for Node.js
Async and the event loop come up in every Node.js interview. Here are the common questions.
Async JavaScript and Event Loop Interview Questions for Node.js
Async and the event loop come up in every Node.js interview. Here are the common questions.
What is the event loop in Node.js?
A single-threaded loop that processes callbacks from completed async operations. It has phases (timers, pending, poll, check, close) and makes Node.js non-blocking by handling I/O asynchronously through libuv.
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 the poll phase. On the next tick, setImmediate usually runs before setTimeout(0) when there are no pending timers.
What is process.nextTick and how does it differ from promises?
process.nextTick callbacks run before promise microtasks, both before macrotasks. It is Node.js-specific and runs first among microtasks. If you need to run code before promises, use nextTick.
What is a microtask vs a macrotask?
Microtasks are promise callbacks and process.nextTick, 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 do you handle errors in async Node.js code?
Use try/catch with async/await, or .catch with promises. Add a global unhandled rejection handler as a safety net, since unhandled rejections crash the process in newer Node.js versions.
The Takeaway
Know the event loop, setTimeout vs setImmediate, process.nextTick vs promises, microtasks vs macrotasks, and error handling in async code. These test real understanding of Node.js's async model and come up in every backend interview.
A single-threaded loop that processes callbacks from completed async operations. It has phases (timers, pending, poll, check, close) and makes Node.js non-blocking by handling I/O asynchronously through libuv.
setTimeout runs in the timers phase after a delay. setImmediate runs in the check phase, right after the poll phase. 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 promise microtasks, both before macrotasks. It runs first among microtasks. Use it when you need to run code before promises on the next tick.
Microtasks are promise callbacks and process.nextTick, 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.
Use try/catch with async/await, or .catch with promises. Add a global unhandled rejection handler as a safety net, since unhandled rejections crash the process in newer Node.js versions.
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.

