Promises & async/await

๐ŸŸข Node.js LTS ๐Ÿ“— Chapter 12 of 49 ๐Ÿ“‚ Phase 4: Asynchronous Node.js ๐Ÿ—“๏ธ 2026 Edition
๐Ÿ“Œ Covered in this chapter: Promise States ยท .then/.catch/.finally ยท async/await ยท Promise.all() ยท Promise.race()

Master JavaScript Promises and the async/await syntax for clean, readable asynchronous Node.js code, including Promise.all and error handling.

1Promises & async/await โ€” What You'll Learn

Master JavaScript Promises and the async/await syntax for clean, readable asynchronous Node.js code, including Promise.all and error handling.

Here's everything this chapter covers, in the order you'll learn it:

  • What a Promise is
  • The three states: pending, fulfilled, rejected
  • .then() for handling success
  • .catch() for handling errors
  • .finally() for cleanup code
  • Promise chaining
  • The async keyword
  • The await keyword
  • Error handling with try/catch inside async functions
  • Promise.all() for running tasks in parallel
  • Promise.allSettled()
  • Promise.race()
  • Sequential vs parallel async tasks
2Working Example
๐Ÿ’ป Example: Promises & async/await
async function loadData() {
  try {
    const data = await Promise.resolve("Data received");
    console.log(data);
  } catch (error) {
    console.error(error.message);
  }
}

loadData();
๐Ÿ’ป Continued Example
// Running multiple async tasks in PARALLEL, not one-by-one
const [users, posts] = await Promise.all([
  fetchUsers(),
  fetchPosts(),
]);
3Best Practices & Common Pitfalls
๐Ÿ’ก Key things to remember:
  • Always wrap await calls in try/catch inside async functions โ€” an unhandled rejection can crash a Node.js process.
  • Use Promise.all() when tasks don't depend on each other, to run them concurrently instead of sequentially (much faster).
โ“ Frequently Asked Questions (FAQ)

Q What's the most important thing to understand about promises & async/await?

Focus on: Promise States ยท .then/.catch/.finally ยท async/await ยท Promise.all() ยท Promise.race(). These are the core building blocks this chapter's examples are built around, and they show up repeatedly in later chapters of this course.

Q Do I need external npm packages for promises & async/await?

Only where explicitly shown in the code examples above (like Express, Zod, or Socket.IO) โ€” otherwise, this chapter relies entirely on Node.js's own built-in capabilities.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on Node.js LTS ยท Last updated August 2026