Bun Local Development Guide
Run JavaScript/TypeScript projects on localhost:3000 using the Bun runtime and built-in dev server.
Bun is an all-in-one JavaScript runtime (a replacement for Node + npm) with built-in package management, bundling, and testing, and it starts the development server very quickly. The common local dev address is http://localhost:3000.
Quick Start
curl -fsSL https://bun.sh/install | bash
bun create vite my-app
cd my-app
bun install
bun devDefault localhost
| Scenario | Address |
|---|---|
bun dev / Vite template | http://localhost:5173 or 3000 |
Bun.serve() example | http://localhost:3000 |
The port is determined by the terminal output or the port in the code.
Built-in HTTP Server
const server = Bun.serve({
port: 3000,
fetch(req) {
return new Response('Hello from Bun on localhost');
},
});
console.log(`http://localhost:${server.port}`);Comparison with Node.js
| Item | Bun | Node.js |
|---|---|---|
| Installation Tool | Built-in bun install | Requires npm/pnpm |
| Startup Speed | Generally faster | Mature ecosystem |
| Compatibility | Most npm packages available | Most comprehensive |
Frequently Asked Questions
Port Occupied
Change port: 3001 or terminate the process occupying 3000.
Some npm Packages Incompatible
Fallback to Node.js runtime or check Bun Compatibility.
Summary
Bun is suitable for developers seeking speed in TS/JS local development, with the dev server typically running on localhost:3000 or 5173, gradually replacing the Node + npm workflow.