Docs
/
Node Express
Chapter 5
05 — Async Patterns & Error Handling
Core Concepts
- Callbacks — the original Node async pattern (error-first convention)
- Promises — cleaner chaining,
.then()/.catch() - async/await — syntactic sugar for Promises (recommended)
- Error-first callback —
(err, result) => {}convention - try/catch — catch errors in async/await
- Unhandled rejections —
process.on('unhandledRejection')for uncaught Promise errors - Concurrency —
Promise.all,Promise.allSettled,Promise.race
Error Handling Rules
- Always handle errors — never swallow them silently
- Use try/catch with async/await
- Add
unhandledRejectionhandler as a safety net - Throw errors (don't return them) — let the caller decide
- Use custom error classes for different error types