Bun
Bun is a JavaScript runtime toolchain that runs JavaScript and TypeScript files and ships a package manager, a test runner, and a bundler in one bun executable. The package manager also works on its own, so an existing Node.js project can install its dependencies with Bun without switching runtimes.
Bun is designed as a drop-in replacement for Node.js. It runs on JavaScriptCore, the engine Apple develops for Safari, and its compatibility with Node.js built-in modules is still a work in progress. Its bun install command reads the same package.json files as npm and pnpm, and bun test follows the API of Jest.
Installation and Setup
Bun is installed once per machine. On macOS and Linux, Bun’s documentation recommends the official install script:
$ curl -fsSL https://bun.com/install | bash
On Windows, run this in PowerShell:
PS> powershell -c "irm bun.sh/install.ps1|iex"
Next, confirm the installed version:
$ bun --version
1.4.4
Key Features
- Runs
.ts,.tsx, and.jsxfiles directly by converting them to JavaScript before execution. - Installs npm packages into
node_modulesand records exact versions in abun.locklockfile. - Skips the lifecycle scripts of dependencies, such as
postinstall, unless the project trusts the package. - Runs Jest-compatible tests written with
test()andexpect()from thebun:testmodule. - Bundles code for browsers, Bun, or Node.js with
bun build.
Usage
Say a shop’s project needs Prettier to format its code. The add command with -d installs it and saves it under devDependencies:
$ bun add -d prettier
bun add v1.4.4 (38afee6c8)
installed [email protected] with binaries:
- prettier
1 package installed [3.00ms]
The project’s cart.js module exports a cartTotal() function. A file named cart.test.js checks it with two tests:
import { expect, test } from "bun:test";
import { cartTotal } from "./cart.js";
test("adds up price times quantity", () => {
const items = [
{ price: 5, quantity: 2 },
{ price: 12.5, quantity: 1 },
];
expect(cartTotal(items)).toBe(22.5);
});
test("returns 0 for an empty cart", () => {
expect(cartTotal([])).toBe(0);
});
The test command finds every test file in the project and runs it:
$ bun test
bun test v1.4.4 (38afee6c8)
2 pass
0 fail
2 expect() calls
Ran 2 tests across 1 file. [3.00ms]
After cloning the project, a teammate installs every dependency at the versions in the lockfile:
$ bun install
To run a package’s command once without adding it to the project, use bun x or its alias bunx:
$ bunx cowsay "Hello, Bun!"
To bundle a module and its imports into a dist folder, pass an entry point to build:
$ bun build ./cart.js --outdir ./dist
Bundled 1 module in 3ms
cart.js 140 bytes (entry point)
For every command and option, see the Bun documentation.
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 6, 2026