# Callbacks & Error-First Convention — Node.js

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

> Node's original async style, and why it can get messy.

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