Learn

bun in practice

The all-in-one runtime: package manager, bundler, test runner, and Node alternative.

bun is not just a package manager: it is a full JavaScript runtime that aims to replace Node, npm, and several auxiliary tools (bundler, test runner) in a single binary written in Zig.

What bun does in a single tool

FeaturebunSeparate equivalent
JavaScript runtimeyesNode.js
Package manageryesnpm / pnpm
BundleryesVite / esbuild / Rollup
Test runneryesVitest / Jest
TypeScript transpilernativetsc / ts-node

The result: fewer dependencies, less configuration, and execution speed often faster than Node.

Installing bun

On macOS and Linux:

shell
curl -fsSL https://bun.sh/install | bash

On Windows (PowerShell):

shell
powershell -c "irm bun.sh/install.ps1 | iex"

Via npm (alternative):

shell
npm install -g bun

Verify the installation:

shell
bun --version

Common commands

Install dependencies for an existing project:

shell
bun install

Add a package:

shell
bun add react

Add a devDependency:

shell
bun add -d typescript

Run a script:

shell
bun run dev
shell
bun dev

Execute a file directly (without node):

shell
bun run index.ts

Run tests:

shell
bun test

Run a one-off command:

shell
bunx create-next-app my-app

Remove a package:

shell
bun remove lodash

Why bun is so fast

bun is written in Zig, a low-level language with no garbage collector. It uses the JavaScriptCore engine (the engine behind Safari), known for fast startup. Its package installation is aggressively parallelized and uses its own binary cache format (bun.lockb).

On public benchmarks, bun installs dependencies 5 to 20 times faster than npm, and 2 to 5 times faster than pnpm.

The bun lockfile

bun generates a bun.lockb file (binary format, not human-readable). If you need to inspect the pinned versions, use:

shell
bun pm ls

Compatibility

bun is compatible with the npm ecosystem at ~95%. Most packages work without modification. Remaining edge cases: some native packages (.node bindings) and tools very specific to Node. In 2026, compatibility improves with every release.

Official bun documentation Node.js API compatibility

Check off steps to unlock what comes next

Back to course