Configuration
new BunAdapter({ trustProxy: true, bodyLimit: '1mb', serve: { idleTimeout: 120, maxRequestBodySize: 128 * 1024 * 1024, shutdownTimeout: 10_000, reusePort: true, },});Adapter options
Section titled “Adapter options”| Option | Default | What it does |
|---|---|---|
trustProxy |
false |
Use X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host for req.ip, req.protocol and req.hostname. Turn on behind a load balancer. |
bodyLimit |
'100kb' |
Size limit for the built-in JSON and urlencoded parsers, matching Express. Bodies over the limit get a 413. |
serve |
Options forwarded to Bun.serve(), below. |
serve options
Section titled “serve options”| Option | Default | What it does |
|---|---|---|
idleTimeout |
120 |
Seconds a connection may sit idle before Bun closes it. Max 255, 0 disables. Bun’s own default is 10, which is too short for slow handlers. |
maxRequestBodySize |
128 MiB | Hard cap enforced by Bun before the adapter sees the body. |
shutdownTimeout |
10000 |
Milliseconds app.close() waits for in-flight requests before dropping them. |
reusePort |
false |
Let several processes bind the same port (cluster mode). |
tls |
TLS options. Set automatically from Nest’s httpsOptions. |
|
development |
Bun’s development mode (verbose errors). |
Nest application options
Section titled “Nest application options”These NestFactory.create() options are honored:
httpsOptionsmapskey,cert,caandpassphraseto Bun’s TLS config.rawBody: trueexposes the unparsed body asreq.rawBody(aBuffer).bodyParser: falseskips the default parsers.forceCloseConnections: truedrops in-flight requests onapp.close()instead of draining.return503OnClosing: trueanswers503withConnection: closewhile shutting down.corsandapp.enableCors()use thecorspackage with the same options as Express.
Listening
Section titled “Listening”await app.listen(3000); // all interfacesawait app.listen(3000, '127.0.0.1'); // one interfaceawait app.listen(0); // random free port; read it with app.getUrl()await app.listen('/tmp/api.sock'); // unix socketapp.getHttpServer() returns a BunHttpServer: an EventEmitter with listen, close, address() and a bun property holding the live Bun.serve() instance.