How do you handle unhandled promise rejections?
Model answer
Catch errors where they happen with try/catch or .catch(). As a safety net, listen to process.on('unhandledRejection') to log, and in modern Node an unhandled rejection crashes the process by default. For Express 5, errors from async handlers are passed to the error middleware automatically. Log, then exit and let a process manager restart in a clean state.
Learn this topic
Async JavaScript in Node: Promises, async/await and the Event Loop in the course Node.js and Express: Build a Back End API from Scratch.
Sign in to add your own answer.