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.14
Linux & macOSWindowsView install scriptcurl -fsSL https://bun.sh/install | bash
powershell -c "irm bun.sh/install.ps1 | iex"
USED BY
BundlerExpressPostgresWebSocketsBundling 10,000 React componentsBuild time in milliseconds (Linux x64, Hetzner)
Bunv1.3.0269.1 msRolldownv1.0.0-beta.42494.9 msesbuildv0.25.10571.9 msFarmv1.0.51,608 msRspackv1.5.82,137 msView benchmark →Express.js 'hello world'HTTP requests per second (Linux x64)
bun: 59,026 requests per second59,026deno: 25,335 requests per second25,335node: 19,039 requests per second19,039Bunv1.2Denov2.1.6Node.jsv23.6.0View benchmark →WebSocket chat serverMessages sent per second (Linux x64, 32 clients)
bun: 2,536,227 messages sent per second2,536,227deno: 1,320,525 messages sent per second1,320,525node: 435,099 messages sent per second435,099Bun.serve()v1.2Deno.serve()v1.2.6ws (Node.js)v23.6.0View benchmark →Load a huge tableQueries per second. 100 rows x 100 parallel queries
bun: 28,571 queries per second28,571node: 14,522 queries per second14,522deno: 11,169 queries per second11,169Bunv1.2.22Node.jsv24.8.0Denov2.5.1View benchmark →Four tools, one toolkitUse 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.
JavaScript RuntimeStarts 3x faster than Node.jsA fast JavaScript runtime designed as a drop-in replacement for Node.js$ bun ./index.ts✓Node.js API compatibility✓TypeScript, JSX & React (zero config)✓Comprehensive builtin standard library✓PostgreSQL, Redis, MySQL, SQLite✓Hot & watch mode built-in✓Environment variables with .envBun's single file executables & fast start times are great for CLIs.
Learn about single file executablesBun's all-in-one toolkit makes Railway's serverless functions fast and easy to use.
Deploy on RailwayMidjourney uses BunBun's built-in WebSocket server helps Midjourney publish image generation notifications at scale.
Learn about Bun's WebSocket serverBun provides extensive builtin APIs and tooling
Builtin Core FeaturesEssential runtime capabilities
BunNodeDenoNode.js compatibilityAiming to be a drop-in replacement for Node.js appsBuilt-in performance and native APIs designed for production
BunNodeDenoPostgreSQL, MySQL, and SQLite driversConnect to any SQL database with one fast, unified APIBuilt-in developer tooling
BunNodeDenonpm package managementInstall, manage, and publish npm-compatible dependenciesAPIs that make your life easier as a developer
BunNodeDenoPassword & Hashing APIsbcrypt, argon2, and non-cryptographic hash functionsProduction-ready APIs and tools, built into Bun
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.jsVP of Developer Experience at Cursor (Anysphere)
app/blog/[slug]/page.tsx
import { s3, $, sql } from "bun"; export default async function BlogPage({ params }) { const [post] = await sql` SELECT title, image_key, content FROM posts WHERE slug = ${params.slug} `; const imgUrl = s3.file(post.image_key).presign({•••expiresIn: 3600 }); const wordCount = await $`echo ${post.content} | wc -w`; return ( div> h1>{post.title}h1> img src={imgUrl} /> p>Word count: {wordCount}p> div> );}Full speed full-stackFast 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 appsBun'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.
$ bun init --reactRun bun ./index.html to start a dev server. TypeScript, JSX, React, and CSS imports work out of the box.
Hot Module ReplacementBuilt-in HMR preserves application state during development. Changes appear instantly—no manual refresh needed.
Build for productionBuild optimized bundles with bun build ./index.html --production. Tree-shaking, minification, and code splitting work out of the box.
Learn more about frontend with Bun →$ bun installBun
pnpm
17x slowernpm
29x slowerYarn
33x slowerInstalling dependencies from cache for a Remix app.
View benchmark
Replace yarn with bun install to get 30x faster package installs.
Try it$ bun testBun is a test runner that makes the rest look like test walkers.Bun
Vitest
5x slowerJest+SWC
8x slowerJest+tsjest
18x slowerJest+Babel
20x slowerReplace jest with bun test to run your tests 10-30x faster.
Try itThe 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
index.tsximport { 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: 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()}`);Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →Bun — A fast all-in-one JavaScript runtime,AI智能索引,全网链接索引,智能导航,网页索引
- Bundle, install, and run JavaScript & TypeScript — all in Bun. Bun is a new JavaScript runtime with a native bundler, transpiler, task runner, and npm client built-in.