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.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Async JavaScript and Event Loop Interview Questions for 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.
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.
Still have questions?
Browse all our FAQs or reach out to our support team
