| CARVIEW |
Bun is joining Anthropic & Anthropic is betting on Bun →
Bun is a fast JavaScript
all-in-one toolkit|
Bun is a fast, incrementally adoptable all-in-one JavaScript, TypeScript & JSX toolkit. Use individual tools like bun test or bun install in Node.js projects, or adopt the complete stack with a fast JavaScript runtime, bundler, test runner, and package manager built in. Bun aims for 100% Node.js compatibility.
Install Bun v1.3.7
curl -fsSL https://bun.sh/install | bashpowershell -c "irm bun.sh/install.ps1 | iex"USED BY
Bundling 10,000 React components
Build time in milliseconds (Linux x64, Hetzner)
Express.js 'hello world'
HTTP requests per second (Linux x64)
- bun: 59,026 requests per second59,026
- deno: 25,335 requests per second25,335
- node: 19,039 requests per second19,039
WebSocket chat server
Messages sent per second (Linux x64, 32 clients)
- bun: 2,536,227 messages sent per second2,536,227
- deno: 1,320,525 messages sent per second1,320,525
- node: 435,099 messages sent per second435,099
Load a huge table
Queries per second. 100 rows x 100 parallel queries
- bun: 28,571 queries per second28,571
- node: 14,522 queries per second14,522
- deno: 11,169 queries per second11,169
Four tools, one toolkit
Use them together as an all-in-one toolkit, or adopt them incrementally. bun test works in Node.js projects. bun install can be used as the fastest npm client. Each tool stands on its own.
Test Runner
Replaces Jest & VitestJest-compatible test runner with built-in code coverage and watch mode
$ bun test- ✓Jest-compatible expect() API
- ✓Snapshot testing
- ✓Watch mode & lifecycle hooks
- ✓DOM APIs via happy-dom
- ✓Concurrent test execution
- ✓Built-in code coverage
Who uses Bun?
Claude Code uses Bun
Bun's single file executables & fast start times are great for CLIs.
Railway Functions powered by Bun
Bun's all-in-one toolkit makes Railway's serverless functions fast and easy to use.
Midjourney uses Bun
Bun's built-in WebSocket server helps Midjourney publish image generation notifications at scale.
What's different about Bun?
Bun provides extensive builtin APIs and tooling
Everything you need to build & ship
Production-ready APIs and tools, built into Bun
HTTP & WebSockets
Databases
File System
Testing
Build & Deploy
TypeScript & DX
Security
System Integration
Bun is a JavaScript runtime.
Bun is a new JavaScript runtime built from scratch to serve the modern JavaScript ecosystem. It has three major design goals:
- Speed. Bun starts fast and runs fast. It extends JavaScriptCore, the performance-minded JS engine built for Safari. Fast start times mean fast apps and fast APIs.
- Elegant APIs. Bun provides a minimal set of highly-optimized APIs for performing common tasks, like starting an HTTP server and writing files.
- Cohesive DX. Bun is a complete toolkit for building JavaScript apps, including a package manager, test runner, and bundler.
Bun is designed as a drop-in replacement for Node.js. It natively implements thousands of Node.js and Web APIs, including fs, path, Buffer and more.
The goal of Bun is to run most of the world's server-side JavaScript and provide tools to improve performance, reduce complexity, and multiply developer productivity.
Bun works with Next.js
Lee Robinson
VP of Developer Experience at Cursor (Anysphere)
app/blog/[slug]/page.tsx
Full speed full-stack
Fast frontend apps with Bun's built-in high performance development server and production bundler. You've never seen hot-reloading this fast!
Develop and ship frontend apps
Bun's built-in bundler and dev server make frontend development fast and simple. Develop with instant hot reload, then ship optimized production builds—all with zero configuration.
Start a dev server
Run bun ./index.html to start a dev server. TypeScript, JSX, React, and CSS imports work out of the box.
Hot Module Replacement
Built-in HMR preserves application state during development. Changes appear instantly—no manual refresh needed.
Build for production
Build optimized bundles with bun build ./index.html --production. Tree-shaking, minification, and code splitting work out of the box.
Bun is an npm-compatible package manager.
Bun
pnpm
npm
Yarn
Installing dependencies from cache for a Remix app.
View benchmark
Bun is a test runner that makes the rest look like test walkers.
Bun
Vitest
Jest+SWC
Jest+tsjest
Jest+Babel
The APIs you need. Baked in.
Start an HTTP server
Start a WebSocket server
Read and write files
Hash a password
Frontend dev server
Write a test
Query PostgreSQL
Use Redis
Import YAML
Set cookies
Run a shell script
Call a C function
import { sql, serve } from "bun";
const server = serve({
port: 3000,
routes: {
"/": new Response("Welcome to Bun!"),
"/api/users": async (req) => {
const users = await sql`SELECT * FROM users LIMIT 10`;
return Response.json({ users });
},
},
});
console.log(`Listening on localhost:${server.port}`);const server = Bun.serve<{ authToken: string; }>({
fetch(req, server) {
// use a library to parse cookies
const cookies = parseCookies(req.headers.get("Cookie"));
server.upgrade(req, {
data: { authToken: cookies['X-Token'] },
});
},
websocket: {
// handler called when a message is received
async message(ws, message) {
console.log(`Received: ${message}`);
const user = getUserFromToken(ws.data.authToken);
await db.Message.insert({
message: String(message),
userId: user.id,
});
},
},
});
console.log(`Listening on localhost:${server.port}`);const file = Bun.file(import.meta.dir + '/package.json'); // BunFile
const pkg = await file.json(); // BunFile extends Blob
pkg.name = 'my-package';
pkg.version = '1.0.0';
await Bun.write(file, JSON.stringify(pkg, null, 2));
const password = "super-secure-pa$$word";
const hash = await Bun.password.hash(password);
// => $argon2id$v=19$m=65536,t=2,p=1$tFq+9AVr1bfPxQdh...
const isMatch = await Bun.password.verify(password, hash);
// => true// Run 'bun init --react' to get started
import { serve } from "bun";
import reactApp from "./index.html";
serve({
port: 3000,
routes: {
"/": reactApp,
"/api/hello": () => Response.json({ message: "Hello!" }),
},
development: {
console: true, // Stream browser logs to terminal
hmr: true, // Enable hot module reloading
},
});import { test, expect } from "bun:test";
// Run tests concurrently for better performance
test.concurrent("fetch user 1", async () => {
const res = await fetch("https://api.example.com/users/1");
expect(res.status).toBe(200);
});
test.concurrent("fetch user 2", async () => {
const res = await fetch("https://api.example.com/users/2");
expect(res.status).toBe(200);
});
test("addition", () => {
expect(2 + 2).toBe(4);
});
import { sql } from "bun";
// Query with automatic SQL injection prevention
const users = await sql`
SELECT * FROM users
WHERE active = ${true}
LIMIT 10
`;
// Insert with object notation
const [user] = await sql`
INSERT INTO users ${sql({
name: "Alice",
email: "alice@example.com"
})}
RETURNING *
`;// Import YAML files directly
import config from "./config.yaml";
console.log(config.database.host);
// => "localhost"
// Or parse YAML at runtime
const data = Bun.YAML.parse(`
name: my-app
version: 1.0.0
database:
host: localhost
port: 5432
`);import { serve } from "bun";
serve({
port: 3000,
routes: {
"/": (request) => {
// Read cookies with built-in parsing
const sessionId = request.cookies.get("session_id");
// Set cookies
request.cookies.set("session_id", "abc123", {
path: "/",
httpOnly: true,
secure: true,
});
return Response.json({ success: true });
},
},
});import { redis } from "bun";
// Set a key
await redis.set("greeting", "Hello from Bun!");
console.log(db.query("SELECT 1 as x").get());
// { x: 1 }
import { $ } from 'bun';
// Run a shell command (also works on Windows!)
await $`echo "Hello, world!"`;
const response = await fetch("https://example.com");
// Pipe the response body to gzip
const data = await $`gzip < ${response}`.arrayBuffer();import { dlopen, FFIType, suffix } from "bun:ffi";
// `suffix` is either "dylib", "so", or "dll" depending on the platform
const path = `libsqlite3.${suffix}`;
const {
symbols: {
sqlite3_libversion, // the function to call
},
} = dlopen(path, {
sqlite3_libversion: {
args: [], // no arguments
returns: FFIType.cstring, // returns a string
},
});
console.log(`SQLite 3 version: ${sqlite3_libversion()}`);