Bun is a JavaScript runtime, bundler, test runner, and package manager — all in one binary. It's 3-10x faster than Node.js for most operations and drops in as a replacement.
Why Bun?
-
3x faster npm install (no node_modules sprawl with
bun install) - Built-in bundler — replaces webpack/esbuild
- Built-in test runner — replaces Jest/Vitest
- Native TypeScript — no tsc or ts-node needed
- Node.js compatible — runs most npm packages
Quick Start
# Install
curl -fsSL https://bun.sh/install | bash
# Create project
bun init
# Run TypeScript directly
bun run index.ts
# Install packages (3x faster than npm)
bun install express
HTTP Server (Built-in)
// server.ts
Bun.serve({
port: 3000,
fetch(req) {
const url = new URL(req.url);
if (url.pathname === '/api/hello') {
return Response.json({ message: 'Hello from Bun!' });
}
if (url.pathname === '/api/users' && req.method === 'POST') {
const body = await req.json();
return Response.json({ created: body }, { status: 201 });
}
return new Response('Not Found', { status: 404 });
},
});
console.log('Server running on http://localhost:3000');
File I/O (Fastest in Any Runtime)
// Write
await Bun.write('output.txt', 'Hello, Bun!');
await Bun.write('data.json', JSON.stringify({ key: 'value' }));
// Read
const text = await Bun.file('output.txt').text();
const json = await Bun.file('data.json').json();
const bytes = await Bun.file('image.png').arrayBuffer();
// Stream large files
const file = Bun.file('large.csv');
const stream = file.stream();
SQLite (Built-in!)
import { Database } from 'bun:sqlite';
const db = new Database('myapp.sqlite');
db.run(`CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE
)`);
// Prepared statements
const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
insert.run('Alice', 'alice@example.com');
// Query
const users = db.prepare('SELECT * FROM users').all();
console.log(users);
// Transaction
const insertMany = db.transaction((users) => {
for (const user of users) {
insert.run(user.name, user.email);
}
});
Built-in Test Runner
// math.test.ts
import { expect, test, describe } from 'bun:test';
describe('math', () => {
test('addition', () => {
expect(2 + 2).toBe(4);
});
test('async', async () => {
const result = await fetch('http://localhost:3000/api/hello');
expect(result.status).toBe(200);
});
});
bun test
Bundler
await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
minify: true,
splitting: true,
target: 'browser',
});
Package Manager
bun install # Install all deps
bun add express # Add package
bun remove lodash # Remove package
bun add -d @types/node # Dev dependency
bun update # Update all
Building fast data pipelines? Check out my Apify actors for web scraping at Bun speed, or email spinov001@gmail.com for custom solutions.
Bun or Node.js — which runtime are you using in 2026? Share below!
Top comments (0)