1. Concept library
  2. Backend with Node.js
  3. Module 4: Async patterns

Concept

Promises and async/await

Almost every Node API returns a promise, and async functions let you await them in sequence. Errors become rejections, which propagate to the nearest await inside a try block.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what an unhandled rejection is and what Node does with it
  2. Write a handler that awaits several operations and catches failures
  3. Spot the async call without await or catch

In practice

A few lines that show Promises and async/await doing its job.

JavaScript
import { readFile } from "node:fs/promises";

async function loadConfig(path) {
  try {
    const text = await readFile(path, "utf8");
    return JSON.parse(text);
  } catch (error) {
    if (error.code === "ENOENT") return {};
    throw error;
  }
}

const config = await loadConfig("./config.json");   // top-level await

The common mistake

Watch for

Calling an async function without await or .catch(). A rejection becomes an unhandled rejection, which crashes modern Node processes by default.

What to know first

Your roadmap puts these before Promises and async/await, unless you already know them.

How it stays learned

Once a session shows you understand Promises and async/await, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Promises and async/await.

Next in the moduleError propagation →