Express works with Bun with full Node.js compatibility.
Installation
bun add express
bun add -d @types/express
Basic Server
import express from "express";
const app = express();
const port = 3000;
app.get("/", (req, res) => {
res.send("Hello from Express + Bun!");
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
Run with:
Middleware
import express from "express";
const app = express();
app.use(express.json());
app.post("/api/data", (req, res) => {
res.json({ received: req.body });
});
app.listen(3000);
For better performance, consider using Bun.serve() or lightweight frameworks like Hono or Elysia.