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 dev

Default localhost

ScenarioAddress
bun dev / Vite templatehttp://localhost:5173 or 3000
Bun.serve() examplehttp://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

ItemBunNode.js
Installation ToolBuilt-in bun installRequires npm/pnpm
Startup SpeedGenerally fasterMature ecosystem
CompatibilityMost npm packages availableMost 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.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run