Search docs

Jump between documentation pages.

Bun

The Bun adapter wraps the native Bun.serve API for REST API deployments. You get fast startup, a smaller memory footprint, and first-class TLS and Unix-socket support without extra middleware.

When to choose Bun

  • You want startup measured in milliseconds and lower per-request overhead than Node.
  • You ship a single self-contained binary or a small container.
  • You're fine with Bun 1.2+ (matches the adapter's expectations).

Scaffold

The bun-basic template ships a Bun-native server with bun testand Hey API codegen.

bash
pnpm create daloy@latest my-api --template bun-basic
cd my-api
pnpm dev    # daloy dev --runtime bun (hot-reload)

Install

bash
bun add @daloyjs/core

Minimal server

ts
// src/server.ts
import { serve } from "@daloyjs/core/bun";
import { app } from "./app.ts";

const handle = serve(app, {
  port: 3000,
  hostname: "0.0.0.0",
  idleTimeout: 30,          // seconds; Bun default is 10
  development: false,       // disables Bun's dev error pages in prod
  // unix: "/tmp/daloy.sock",
  // tls: { cert, key },    // HTTPS
});

console.log("listening on " + handle.url);

Hot reload in dev

bash
bun --hot src/server.ts

Dockerfile

docker
FROM oven/bun:1.2-slim AS build
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun build --target=bun src/server.ts --outdir dist

FROM oven/bun:1.2-distroless
WORKDIR /app
COPY --from=build /app/dist ./dist
EXPOSE 3000
CMD ["dist/server.js"]

Gotchas

  • idleTimeout is in seconds, capped at 255. Pass 0 to disable.
  • Some npm packages with native bindings still need Node — test before committing to Bun in production.
  • Bun's built-in routes option is not used by the adapter; routing is owned by DaloyJS so the same REST API stays portable across runtimes.

See also