Skip to content
Learn Netverks

Lesson

Step 13/36 36% through track

promises-node

Promises 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 Promises 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 Promises 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.

Most modern Node APIs expose Promise versions—often under fs/promises or with util.promisify. Chain with .then/.catch or use async/await for readability.

Promise basics

import { readFile } from 'node:fs/promises';

readFile('config.json', 'utf8')
  .then(JSON.parse)
  .then(config => console.log(config.port))
  .catch(err => console.error(err));

Promise.all

Run independent async tasks in parallel—fails fast if any reject. Use Promise.allSettled when you need every result regardless of failures.

Important interview questions and answers

  1. Q: Unhandled promise rejection?
    A: Node emits unhandledRejection—always attach .catch or try/catch around await in async functions.
  2. Q: Promise.all vs sequential await?
    A: all parallelizes independent work; sequential await in a loop waits each iteration—slower for I/O that could overlap.

Self-check

  1. When does Promise.all reject?
  2. Where do fs promise APIs live?

Interview prep

fs.promises vs callback fs?

fs.promises returns Promises for async/await; callback style nests error-first functions—prefer promises in modern code.

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

  • Promise.all fail fast?
  • Unhandled rejection?

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