Skip to main content
Express and other major Node.js HTTP libraries work with Bun out of the box. Bun implements the node:http and node:https modules that Express relies on.
See the Node.js compatibility page for detailed information about which Node.js APIs Bun supports.

Setup

1

Install Express

bun add express
bun add -d @types/express
2

Create a server

src/server.ts
import express from "express";

const app = express();
const port = parseInt(process.env.PORT ?? "3000");

app.use(express.json());

app.get("/", (req, res) => {
  res.send("Hello from Express on Bun!");
});

app.listen(port, () => {
  console.log(`Server running on http://localhost:${port}`);
});
3

Run the server

bun run src/server.ts

Routing

Express routing works identically on Bun:
import express, { Request, Response } from "express";

const app = express();
app.use(express.json());

// GET with route parameter
app.get("/users/:id", (req: Request, res: Response) => {
  res.json({ id: req.params.id });
});

// POST with body
app.post("/users", (req: Request, res: Response) => {
  const { name, email } = req.body;
  res.status(201).json({ name, email });
});

// Router for grouping
const api = express.Router();
api.get("/status", (_req, res) => res.json({ ok: true }));

app.use("/api", api);

app.listen(3000);

Middleware

Express middleware functions work the same way:
import express from "express";

const app = express();

// Built-in middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Custom logging middleware
app.use((req, _res, next) => {
  console.log(`${new Date().toISOString()} ${req.method} ${req.path}`);
  next();
});

// Error handling middleware
app.use((err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
  console.error(err.stack);
  res.status(500).json({ error: err.message });
});

app.get("/", (_req, res) => res.send("OK"));
app.listen(3000);

Performance notes

Express on Bun is faster than Express on Node.js because Bun’s HTTP implementation is more efficient. However, if you are starting a new project and do not need Express compatibility, Bun’s native Bun.serve() API or a Bun-native framework like Elysia or Hono will provide better performance.
import express from "express";

const app = express();
app.get("/", (_req, res) => res.send("Hello!"));
app.listen(3000);
Most Express middleware from the npm ecosystem (body-parser, helmet, morgan, cors, etc.) works with Bun without any changes.

Build docs developers (and LLMs) love