Bun Performance
| Benchmark | Node.js | Bun | Speedup |
|---|---|---|---|
| Startup | ~25ms | ~6ms | 4x |
| npm install | ~10s | ~0.4s | 25x |
| HTTP requests/sec | ~65K | ~105K | 1.6x |
| Bundle (esbuild equiv) | 1.0x | 1.5x | 1.5x |
| TypeScript | Needs ts-node | Native | Zero config |
Package Manager
# Install all dependencies (lockfile-aware)
bun install # 25x faster than npm install
# Add a package
bun add openai
bun add -d typescript
# Remove
bun remove express
# Compatible with package.json and node_modulesNative TypeScript
// No tsconfig needed, no ts-node, no build step
const response: Response = await fetch("https://api.openai.com/v1/models");
const data: { data: Array<{ id: string }> } = await response.json();
console.log(data.data.map(m => m.id));bun run app.ts # Just worksBuilt-in Test Runner
// app.test.ts
import { expect, test } from "bun:test";
test("2 + 2 = 4", () => {
expect(2 + 2).toBe(4);
});
test("fetch works", async () => {
const res = await fetch("https://httpbin.org/get");
expect(res.status).toBe(200);
});bun test # Runs all .test.ts filesBuilt-in Bundler
bun build ./src/index.ts --outdir ./dist --target browserSQLite Built-in
import { Database } from "bun:sqlite";
const db = new Database("mydb.sqlite");
db.run("CREATE TABLE IF NOT EXISTS chats (id INTEGER PRIMARY KEY, prompt TEXT, response TEXT)");
db.run("INSERT INTO chats (prompt, response) VALUES (?, ?)", ["Hello", "Hi there!"]);FAQ
Q: What is Bun? A: Bun is an all-in-one JavaScript/TypeScript runtime with 88,700+ GitHub stars. It replaces Node.js (runtime), npm (package manager), webpack (bundler), and Jest (test runner) in a single fast tool.
Q: Is Bun compatible with Node.js? A: Yes, Bun is largely compatible with Node.js APIs and npm packages. Most Express, Fastify, and Next.js apps work with Bun with minimal changes.
Q: Is Bun free? A: Yes, open-source under MIT license.