# Callbacks & Error-First Convention — Node.js Fundamentals: Modules, Async and Servers

Source: https://www.skillbyai.com/en/nodejs/node-callbacks

> Understand error-first callbacks, Node's original async style, and the pyramid of doom they can create.

## Error-first callbacks

Node's convention: a callback's **first argument** is an error (or `null`), the rest are results.

```javascript
import fs from "node:fs";

fs.readFile("notes.txt", "utf8", (err, data) => {
  if (err) {
    console.error("Failed:", err.message);
    return;
  }
  console.log(data);
});
```

## Callback hell

Nesting callback inside callback inside callback grows a **pyramid of doom** that's hard to read and error-prone. Promises and async/await fix this.
