Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

async-await

async/await in Node

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
beginner

This lesson

This lesson teaches async/await in Node: the syntax, APIs, and habits you need before advancing in Node.js.

Non-blocking APIs are idiomatic Node—callback hell and unhandled rejections still fail production services.

You will apply async/await in Node in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons.

When you can explain the previous lesson's ideas without copying starter code.

async functions return Promises; await pauses until a Promise settles. This is syntactic sugar over promises—but it reads like synchronous code, which helps HTTP handlers and scripts.

Basic pattern

async function loadConfig() {
  const raw = await readFile('config.json', 'utf8');
  return JSON.parse(raw);
}

Error handling

try {
  const config = await loadConfig();
} catch (err) {
  console.error('Failed to load config', err);
  process.exit(1);
}

Top-level await

ESM modules allow await at top level—this playground uses it in main.mjs without wrapping in async main().

Important interview questions and answers

  1. Q: Does await block the thread?
    A: It suspends the async function and yields to the event loop—other callbacks can run; it does not block the entire process like sync sleep.
  2. Q: async without await?
    A: Still returns a Promise—useful when returning promise chains from helpers.

Self-check

  1. What does an async function return if you return a plain number?
  2. Where should you catch errors from await?

Pitfall: Forgetting await returns a Promise object, not the resolved value—log shows Promise { <pending> }.

Interview prep

try/catch with async?

Wrap await in try/catch inside async functions—or use .catch() on the returned Promise at the call site.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • await in loop trap?
  • Top-level await where?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump