Bun
Deploy a NextRush app to Bun using @nextrush/adapter-bun.
@nextrush/adapter-bun connects a NextRush Application to Bun.serve(). Bun runs TypeScript
natively, so there's no separate build step for local development or for the container image
below.
Installation
$ pnpm add nextrush @nextrush/adapter-bun
Minimal deployment
import { createApp } from '@nextrush/core';
import { createRouter } from '@nextrush/router';
import { serve } from '@nextrush/adapter-bun';
const app = createApp();
const router = createRouter();
router.get('/health', (ctx) => ctx.json({ status: 'ok' }));
app.route('/', router);
serve(app, { port: Number(process.env.PORT ?? 8080) });bun run src/index.tsThe `nextrush` meta package defaults to Node.js
nextrush's createApp/listen re-export @nextrush/adapter-node. For Bun, import
createApp from @nextrush/core directly and call serve() from @nextrush/adapter-bun —
as shown above — instead of nextrush's listen().
serve() options that matter in production
ServeOptions (@nextrush/adapter-bun)
| Property | Type | Description |
|---|---|---|
port | number= 8080 | Port to listen on. |
host | string= '0.0.0.0' | Host/interface to bind to. |
timeout | number= 30000 | Request timeout in ms, enforced via `AbortController` (Bun.serve has no built-in per-request timeout). |
maxRequestBodySize | number= 1048576 (1 MB) | Max request body size in bytes, applied at the Bun.serve level. |
shutdownTimeout | number= 30000 | Grace period to drain in-flight requests during `close()` before force-closing. |
development | boolean= false | Enables Bun dev-mode features. |
tls? | { cert, key, ca? } | Enables HTTPS. |
Bun's default body-size limit is 128 MB
Bun.serve() defaults to a 128 MB request body limit. @nextrush/adapter-bun always applies
maxRequestBodySize (default 1 MB, matching @nextrush/adapter-node) to override that —
raise it explicitly for endpoints that accept large uploads.
import { createApp } from '@nextrush/core';
import { createRouter } from '@nextrush/router';
import { serve } from '@nextrush/adapter-bun';
const app = createApp();
const router = createRouter();
router.get('/health', (ctx) => ctx.json({ status: 'ok' }));
app.route('/', router);
const server = await serve(app, {
port: Number(process.env.PORT ?? 8080),
maxRequestBodySize: 10 * 1024 * 1024, // 10 MB
onListen: ({ port }) => console.log(`listening on ${port}`),
});
process.on('SIGTERM', async () => {
await server.close(); // drains in-flight requests, then tears down extensions
process.exit(0);
});Graceful shutdown
server.close() calls Bun.serve()'s stop(), waits up to shutdownTimeout for in-flight
requests to finish, then force-closes remaining connections and tears down extensions. See
Reliability for the full shutdown pattern and which signals to
handle.
Hot reload in development
bun --hot run src/index.tsBun reloads on file change without restarting the process. This is a development convenience —
production deployments should still run under a supervisor (systemd, PM2, or a container
orchestrator) rather than --hot.
Deploying
Bun apps deploy the same way as any long-running Node-compatible process — a VM, a container, or a platform with native Bun support (e.g. Railway, Fly.io). To containerize:
FROM oven/bun:1-alpine AS runtime
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --production
COPY src/ ./src/
ENV NODE_ENV=production
ENV PORT=8080
EXPOSE 8080
USER bun
CMD ["bun", "run", "src/index.ts"]This Dockerfile is illustrative, not verified
Unlike the Node.js Dockerfile in Docker — which was
actually built and health-checked against a running container as part of this documentation's
verification gate — this Bun Dockerfile has not been build-tested here. Verify it against your
own bun.lock and Bun version before relying on it.
Requirements
- Bun >= 1.0.0
@types/bunas a dev dependency for editor/TypeScript support (already declared in@nextrush/adapter-bun's owndevDependencies)
Related
- Node.js — the default runtime target
- Docker — a verified, build-tested Dockerfile (Node.js)
- Reliability — graceful shutdown, health checks, timeouts