---
title: "Migrate from Node.js"
description: "Find and rewrite Node.js APIs that have a Bun equivalent with bun n2b, and migrate a project with bun migrate"
---

`bun n2b` scans a project for Node.js APIs that have a faster or simpler Bun equivalent, such as `fs.readFile` for `Bun.file().text()` or `child_process` for `Bun.spawn`, and can rewrite them. `bun migrate` moves a whole Node.js project to Bun.

```bash terminal icon="terminal"
bun n2b
```

Each finding has a rule, a severity, a message and, when one exists, the replacement code.

## Rewrite code

```bash terminal icon="terminal"
# apply the safe rewrites
bun n2b --fix

# also apply the rewrites that change behavior in edge cases
bun n2b --aggressive
```

## Reports

`--report` selects `text` (default), `json`, `jsonl`, `md` or `sarif`.

```bash terminal icon="terminal"
bun n2b --report=json > n2b.json
bun n2b --report=sarif > n2b.sarif
```

`--dry-run` previews the rewrites without writing files, and `--since <ref>` scans only the files changed since a git ref. `bun n2b rules` lists every rule with its category and documentation link.

## Migrate a project

`bun migrate` applies every n2b rewrite, converts pnpm workspaces, catalogs and overrides to `package.json`, removes the other lockfiles and runs `bun install`.

```bash terminal icon="terminal"
# print the migration plan and change nothing
bun migrate --dry-run

bun migrate
```

`bun migrate` is the same as `bun n2b migrate`.

`bun n2b --help` lists every command and flag.

`bun n2b` and `bun migrate` always run the built-in commands. Use `bun run n2b` or `bun run migrate` to run a project's scripts of the same name.
