Bun.serve(), and run it — all without any compilation step.
You need Bun installed before starting. See Installation if you haven’t done that yet.
1
Create a new project
Run Bun prompts you to choose a template. Select Blank for this guide:This creates a
bun init to scaffold a new project. Pass a directory name to create it in a subdirectory:my-app/ directory with a minimal TypeScript project. The tsconfig.json is configured for Bun and includes type definitions automatically.2
Run the default file
Move into the project directory and run the generated Bun executes TypeScript directly — no compilation step, no
index.ts:tsc, no build output.3
Write an HTTP server
Replace the contents of Run it:Open http://localhost:3000 in your browser. You should see
index.ts with a simple HTTP server using Bun.serve():index.ts
Hello from Bun!.Bun.serve() accepts a fetch handler that receives a standard Request and must return a Response. These are the same Web APIs used in service workers and edge runtimes.4
Add routing
Bun.serve() also supports a routes object for declarative routing without a framework:index.ts
5
Add a package.json script
Open Now start the server with:
package.json and add a start script so you can run the server with a short command:package.json
bun run is roughly 28x faster than npm run — 6ms vs 170ms of overhead per invocation. For projects with many scripts, this adds up quickly.TypeScript
Learn how Bun handles TypeScript natively, including recommended tsconfig settings.
HTTP server API
Explore the full
Bun.serve() API: WebSockets, TLS, streaming responses, and more.Package manager
Install npm packages with
bun add and manage dependencies faster than npm.Test runner
Write and run Jest-compatible tests with
bun test.