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.
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.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.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.Add routing
Bun.serve() also supports a routes object for declarative routing without a framework:index.ts
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.