CodePark/ questions / Errors, process & signals
START PRACTICINGPRACTICE
Backend question · Node.js › Errors, process & signals

On Node 22 with default flags and no unhandledRejection listener, what happens?

Promise.reject(new Error("x"));
setTimeout(() => console.log("still alive"), 100);
The process prints the error and exits with code 1 before the timer fires

The process prints the error and exits with code 1 before the timer fires.

Since Node 15, the default
--unhandled-rejections mode is throw. In this mode, Node raises an unhandled rejection as an uncaught exception. The uncaught exception crashes the process with exit code 1.

"It logs
still alive, after a deprecation warning about the rejection" is wrong for Node 22. Printing a warning and continuing was the behavior in Node 14 and earlier.