Skip to content

NestJS on Bun, natively

A NestJS Bun adapter that runs your app straight on Bun.serve(). Swap one line, keep every controller, pipe, guard and filter, and drop the build step.

Why not just run Express on Bun?

You can, and it works. But every request pays for a Node compatibility layer. Going straight to Bun's native server removes it, and brings Web-standard primitives with it.

Faster than Express and Fastify

Same app, same runtime, same machine: more requests per second on both JSON reads and JSON writes.

One-line migration

Pass new BunAdapter() to NestFactory.create(). Controllers, pipes, guards, filters, middleware and @Res() handlers stay as they are.

Web standards underneath

Requests are Web Requests, responses become Web Responses, files stream with zero-copy Bun.file(). Express-shaped req/res keep the ecosystem working.

Tests without sockets

adapter.fetch(new Request(...)) runs a request through the full Nest pipeline in-process. No supertest, no port, no flakiness.

Benchmarks

GET /users/:id JSON read

  1. platform-express93k
  2. platform-fastify116k
  3. @nestbun/platform119k
  4. Bun.serve · no framework158k

POST /users JSON write, body parsed

  1. platform-express72k
  2. platform-fastify92k
  3. @nestbun/platform98k
  4. Bun.serve · no framework154k
Requests per second, higher is better. One Nest controller, three adapters, one runtime. Apple M-series laptop, Bun 1.4, 64 connections, 3-second runs, load generator in a separate process. bun run bench reproduces it.
View as table
AdapterGET /users/:idPOST /users
platform-express93,449 req/s71,763 req/s
platform-fastify116,358 req/s91,533 req/s
@nestbun/platform119,022 req/s98,124 req/s
Bun.serve157,694 req/s153,660 req/s

Methodology and how to reproduce →

What works today

Every item is covered by an integration test that boots a real Nest application on the adapter.

Routing and decorators

Params, wildcards, @All, HEAD → GET fallback, first-match order like Express. @Body, @Query, @Param, @Headers, @Ip, @Req, @Res, @Next, @Redirect, @Header, @HttpCode.

Body parsing

JSON and urlencoded by default, text and raw on request, rawBody for webhooks, size limits with 413, Express-identical 400 shapes for bad JSON.

Middleware, prefix, versioning

MiddlewareConsumer with forRoutes, exclude and method scoping, app.use(), next(err), global prefix, URI / header / media-type versioning, CORS.

Streaming

Server-Sent Events with disconnect detection, StreamableFile, manual res.write(), zero-copy file sends.

Static files and views

useStaticAssets with ETag, Last-Modified and 304; ejs, hbs, pug or any render() function.

Ecosystem and lifecycle

@nestjs/swagger and @nestjs/testing untouched. HTTPS, graceful shutdown with a drain timeout, forceCloseConnections, unix sockets.

Full compatibility table →