Skip to content

Overview

bunway brings Express-compatible routing to Bun without sacrificing Bun's native speed. The goal is simple: if you know Express, you know bunway.

Express Compatibility

bunway uses the exact same (req, res, next) handler signature as Express. Your existing middleware patterns work here.

Who is bunway for?

  • Express developers wanting Bun's speed without learning a new API
  • Teams migrating Node.js apps to Bun
  • Anyone who prefers the battle-tested Express patterns over newer abstractions

Goals

  • Express-compatible – same (req, res, next) signature, familiar middleware patterns
  • Bun-native – built on Bun's Fetch primitives (Request, Response, Bun.serve)
  • Batteries included – 19 middleware covering most production needs
  • Zero dependencies – pure Bun, no Node polyfills

Current capabilities

bunway ships with everything you need for production apps:

Core

  • bunway() factory with app.listen()
  • Express-compatible (req, res, next) handler signature
  • BunRequest and BunResponse helpers
  • Sub-routers with middleware inheritance
  • Router finalizer that merges middleware headers
  • Graceful shutdown via app.close()
  • Native HTTPS/TLS support
  • X-Forwarded-Proto support behind reverse proxies

Built-in Middleware

MiddlewareDescriptionExpress Equivalent
json()JSON body parsingexpress.json()
urlencoded()URL-encoded body parsingexpress.urlencoded()
text()Text body parsingbody-parser.text()
cors()CORS handlingcors
helmet()Security headershelmet
session()Session managementexpress-session
cookieParser()Cookie parsingcookie-parser
compression()Response compressioncompression
serveStatic()Static file servingexpress.static()
rateLimit()Rate limitingexpress-rate-limit
csrf()CSRF protectioncsurf
passport()Authenticationpassport
logger()Request loggingmorgan
upload()File uploads (multipart)multer
timeout()Request timeoutconnect-timeout
hpp()HPP protectionhpp
validate()Request validationexpress-validator
errorHandler()Error handlingCustom middleware

Quick example

ts
import bunway, { cors, json, helmet, session, logger } from "bunway";

const app = bunway();

// Familiar middleware stack
app.use(logger("dev"));
app.use(cors({ origin: true }));
app.use(helmet());
app.use(json());
app.use(session({ secret: "keyboard cat" }));

// Express-style routes
app.get("/", (req, res) => res.json({ message: "Hello bunway!" }));

app.get("/users/:id", (req, res) => {
  res.json({ id: req.params.id });
});

app.listen({ port: 3000 });

Request & Response

  • Content Negotiation — RFC 7231 quality-value parsing for Accept headers
  • Regex Routes — use RegExp as route patterns with named capture groups
  • Catch-all Routesapp.all("*", handler) for 404 handlers
  • Cache Validationreq.fresh / req.stale for 304 responses
  • Range Requestsreq.range() + automatic res.sendFile() partial content (206)
  • JSONPres.jsonp() for legacy cross-domain support
  • Cross-Referencesreq.res, res.req, res.app for Express parity
  • Array Pathsapp.use(['/v1', '/v2'], router) for multi-path mounting
  • Sub-App Mountingapp.mountpath property and app.path() method for mounted sub-apps

What's next?

Core features, request/response completeness, and security middleware are done. Active development focuses on:

  • Developer experience — SSE helpers, response time, request ID
  • Performance — continued optimization and benchmarking

See Roadmap & Contributions for the full picture.

Philosophy

  • Express patterns, Bun speed: Familiar APIs, native performance
  • Community-led: We build what developers actually need
  • Transparent: Full TypeScript support with documented types

Ready to build? Continue with Getting Started or jump to the Express Migration Guide.