Why Bun
Bun is a JavaScript runtime, package manager, bundler, and test runner — all in one. Written in Zig with JavaScriptCore engine, it is 3-10x faster than Node.js for most tasks.
Install
curl -fsSL https://bun.sh/install | bash
Run JavaScript/TypeScript
# Run TypeScript directly — no tsc needed
bun run server.ts
# Run JSX
bun run app.tsx
Package Manager (Fastest)
# Install dependencies (10-100x faster than npm)
bun install
# Add package
bun add express
# Dev dependency
bun add -d typescript
HTTP Server
const server = Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url);
if (url.pathname === '/api/users') {
const users = await getUsers();
return Response.json(users);
}
return new Response('Hello from Bun!', { status: 200 });
},
});
console.log(`Server running at http://localhost:${server.port}`);
Built-in SQLite
import { Database } from 'bun:sqlite';
const db = new Database('myapp.db');
db.run('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)');
db.run('INSERT INTO users (name) VALUES (?)', ['Alice']);
const users = db.query('SELECT * FROM users').all();
Test Runner
import { test, expect } from 'bun:test';
test('2 + 2', () => {
expect(2 + 2).toBe(4);
});
test('fetch works', async () => {
const res = await fetch('https://jsonplaceholder.typicode.com/todos/1');
expect(res.status).toBe(200);
});
bun test
Bundler
bun build ./src/index.ts --outdir ./dist --target browser
Key Features
- Runtime — Node.js compatible, runs TypeScript natively
- Package manager — 10-100x faster than npm
- Bundler — built-in, replaces webpack/esbuild
- Test runner — Jest-compatible, built-in
- SQLite — built-in database
- File I/O — Bun.file() is 10x faster than fs
- MIT license — free
Resources
Need to extract JavaScript ecosystem data, npm stats, or runtime benchmarks? Check out my Apify tools or email spinov001@gmail.com for custom solutions.
Top comments (0)