How do you handle errors in Node.js, including in async code and at the process level?
Node has several error channels and you need to cover all of them.
- Synchronous code —
try/catch. - Promises and async/await —
try/catcharound theawait, or.catch()on the chain. In Express 4 an async route handler that throws is not caught by the framework, so you need a wrapper that forwards the rejection tonext(err); Express 5 handles it natively. - Callbacks — the error-first convention,
(err, result). Checkerrbefore anything else and return early. - EventEmitters — listen for the
'error'event. An unhandled'error'event throws and crashes the process, which is deliberate.
At the process level: attach handlers for uncaughtException and unhandledRejection, but use them only to log and then exit cleanly — not to keep running. After an uncaught exception the process is in an unknown state, and continuing risks corrupting data.
Note: Distinguish operational errors, such as a failed network call, which you handle and retry, from programmer errors such as a TypeError, which you should let crash so a supervisor restarts the process.





