Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

callbacks-review

Callbacks review

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

This lesson

This lesson teaches Callbacks review: the syntax, APIs, and habits you need before advancing in Node.js.

Teams ship Callbacks review on every Node.js codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Callbacks review 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.

Node's APIs were designed with error-first callbacks: (err, result) => {}. If err is truthy, handle the error; otherwise use result. Promises and async/await wrap these today, but legacy code and some core patterns still use callbacks.

Error-first pattern

import fs from 'node:fs';
fs.readFile('file.txt', 'utf8', (err, data) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(data);
});

Callback hell

Nested callbacks for sequential async steps become hard to read—promises and async/await flatten the flow. Recognize callbacks in older tutorials and npm docs.

Important interview questions and answers

  1. Q: Why error-first?
    A: Convention ensures errors are never ignored as a forgotten return value—first argument is always err or null.
  2. Q: util.promisify?
    A: Converts callback-style functions to promise-returning wrappers for async/await.

Self-check

  1. In error-first callbacks, what does a truthy first argument mean?
  2. Why prefer promises for new 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

  • Callback hell fix?
  • Error-first callback?

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