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 rejectionsprocess.on('unhandledRejection') for uncaught Promise errors
  • ConcurrencyPromise.all, Promise.allSettled, Promise.race

Error Handling Rules

  1. Always handle errors — never swallow them silently
  2. Use try/catch with async/await
  3. Add unhandledRejection handler as a safety net
  4. Throw errors (don't return them) — let the caller decide
  5. Use custom error classes for different error types