errors
An uncaught rejection ends the process That is better than continuing with broken state
try and await
try {
await riskyWork();
} catch (err) {
console.error(err);
process.exitCode = 1;
}
Setting exitCode lets the current work finish
Calling process.exit() immediately cuts it off
Error subclasses
Built in errors carry a code field
Filesystem errors expose ENOENT , EACCES , and friends
Branch on the code, not on the message text
Rejections
async functions return rejected promises on throw
Forgetting await drops that rejection on the floor
Attach a handler or await the call
Uncaught events
Process level handlers are a last resort Log, flush, and exit Trying to continue after an unknown exception produces corrupted output
Next
Patterns in 10 recipes
Posted