> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# node-callback-api

> A Node.js fs, dns, crypto or zlib API is called with a callback instead of its promise form.

## What it flags

A call such as `fs.readFile(path, 'utf8', (err, text) => ...)`, `dns.lookup(host, cb)`, `crypto.randomBytes(16, cb)` or `zlib.gzip(data, cb)` that passes an inline callback to a Node.js API with a promise form. The callee must resolve to the built-in module through an `import`, `import * as`, named import or `require`, so a project function with the same name is not reported. Covered members:

* `fs`: `access`, `appendFile`, `chmod`, `chown`, `copyFile`, `cp`, `lstat`, `mkdir`, `mkdtemp`, `readFile`, `readdir`, `readlink`, `realpath`, `rename`, `rm`, `rmdir`, `stat`, `symlink`, `truncate`, `unlink`, `utimes`, `writeFile`;
* `dns`: `lookup`, `resolve`, `resolve4`, `resolve6`, `resolveCname`, `resolveMx`, `resolveNs`, `resolveSrv`, `resolveTxt`, `reverse`;
* `crypto`: `generateKeyPair`, `pbkdf2`, `randomBytes`, `scrypt`;
* `zlib`: `brotliCompress`, `brotliDecompress`, `deflate`, `deflateRaw`, `gunzip`, `gzip`, `inflate`, `unzip`.

It stays quiet for `fs/promises` and `fs.promises`, sync forms, calls whose result is kept, calls without an inline function as the last argument, callbacks that pass their error to the enclosing function's own callback (such as a custom `lookup` hook for an http agent, which must keep the callback contract), `fs.exists` (reported by [deprecated-node-api](https://loadwise.mintlify.site/rules/maintainability/deprecated-node-api.md)) and `child_process.exec`/`execFile`, whose callback is often used to read the output of a failed command.

## How to review

Use `node:fs/promises` or `node:dns/promises`, or wrap a crypto or zlib function once with `util.promisify`, then `await` it inside `try`/`catch`:

```ts theme={null}
import { readFile } from 'node:fs/promises';

const text = await readFile(path, 'utf8');
```

Callers of a callback-style function must change too, so there is no automatic fix.

## Configuration

Set the rule to `"off"` in `loadwise.config.json` to drop its findings:

```json theme={null}
{
  "rules": { "node-callback-api": "off" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.