Skip to content

Search docs

Jump between documentation pages.

Browse docs

Deno

The Deno adapter wraps Deno.serve: the stable, modern entry point that replaced the old Deno.serveHttp. It handles SIGTERM/SIGINT for you and also accepts an AbortSignal, the pattern Deno itself recommends.

Deno adapter stack
Your DaloyJS Approutes · hooks · handlers
Deno adapterserve(app) wraps Deno.serve
signalonListencert/key
Deno runtimestable Deno.serve, TS built in
serve() drives the stable Deno.serve, listens for SIGTERM/SIGINT, and also stops when an optional AbortSignal fires. The same src/server.ts runs locally and in a container.

When to choose Deno

  • You want a web-standard runtime with TypeScript built in and no transpile step.
  • You self-host in a container running the official Deno image.
  • You like Deno's permissions model and don't need the full npm ecosystem.
  • You are fine with an upstream runtime in maintenance mode. For a new project with a long life ahead, Node, Bun, or Cloudflare Workers are the safer picks today.

Scaffold

The deno-basic template ships a Deno-native server with a deno.json import map, watch-mode dev, and deno test.

bash
pnpm create daloy@latest my-api --template deno-basic
cd my-api
deno task dev    # deno run --allow-net --allow-env --allow-read --watch

Install

The same source ships to two registries: npm as @daloyjs/core and JSR as @daloyjs/daloy. The deno-basic template loads the npm package through Deno's npm: specifier, the same package the Node, Bun, Workers, and Vercel templates install, so it does not depend on JSR's hosting:

jsonc
// deno.json (what deno-basic ships)
{
  "imports": {
    "@daloyjs/core":      "npm:@daloyjs/core@^1",
    "@daloyjs/core/deno": "npm:@daloyjs/core@^1/deno",
    "zod":                "npm:zod@^4.6.6"
  }
}

Prefer JSR? It is still published from every release, with the same import names:

jsonc
// deno.json (JSR instead of npm)
{
  "imports": {
    "@daloyjs/core":      "jsr:@daloyjs/daloy@^1",
    "@daloyjs/core/deno": "jsr:@daloyjs/daloy@^1/deno",
    "zod":                "npm:zod@^4.6.6"
  }
}

Minimal server

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

serve(app, {
  port: 3000,
  hostname: "0.0.0.0",
  onListen: ({ hostname, port }) =>
    console.log(`listening on http://${hostname}:${port}`),
  // HTTPS:
  // cert: Deno.readTextFileSync("./cert.pem"),
  // key:  Deno.readTextFileSync("./key.pem"),
});

That is all you need for graceful shutdown. serve() listens for SIGTERM and SIGINT itself (handleSignals defaults to true), drains your app.onShutdown hooks for up to shutdownTimeoutMs (default 10 seconds), and then stops Deno.serve so in-flight requests can finish. Do not add your own Deno.addSignalListener calls on top.

To stop the server from your own code, for example in a test, use the handle serve() returns or pass an AbortSignal:

ts
const ac = new AbortController();
const server = serve(app, {
  port: 0,               // let the OS pick a free port
  handleSignals: false,  // tests manage their own lifecycle
  signal: ac.signal,     // aborting this also shuts down
});

// later
await server.shutdown(); // or ac.abort()

Other options: onError returns a fallback Response when the handler itself throws, and shutdownTimeoutMs changes the drain budget. The full list is in the API reference.

Run it

bash
deno run --allow-net --allow-env --allow-read src/server.ts

Dockerfile

docker
FROM denoland/deno:distroless
WORKDIR /app
COPY . .
EXPOSE 3000
CMD ["run", "--allow-net", "--allow-env", "--allow-read", "src/server.ts"]

The container route keeps working whatever happens to Deno Deploy. Run it on any container host: Fly.io, Render, Railway, Google Cloud Run, Azure Container Apps, or your own Kubernetes.

Moving off Deno Deploy

Your DaloyJS app does not change when you move: routes, schemas, and hooks only ever see Request -> Response. Only the entry file changes. Pick a target:

Cloudflare Workers

The closest match to Deno Deploy (global, per-request, no servers), and Cloudflare offers migration help to paying Deno Deploy customers. Swap the entry file for the Workers one:

ts
// src/index.ts
import { toFetchHandler } from "@daloyjs/core/cloudflare";
import { app } from "./app.ts";

export default toFetchHandler(app);

Then follow the Cloudflare Workers guide for wrangler.jsonc, secrets, and bindings. Replace Deno.env.get(...) with Worker bindings and Deno.* file APIs with R2 or KV.

Self-hosted Deno in a container

Keep src/server.ts exactly as it is and ship the Dockerfile above. This is the smallest change, but you stay on a runtime in maintenance mode.

Node or Bun

Import serve from @daloyjs/core/node or @daloyjs/core/bun instead of /deno, swap the jsr:/npm: import map for a package.json, and replace Deno.* APIs with their Node equivalents. See the Node and Bun guides.

Whichever you pick, run your contract tests against the new entry before you switch traffic. The app should answer the same way it did on Deno Deploy.

Gotchas

  • Do not use Deno.serveHttp. It is deprecated. The DaloyJS adapter uses Deno.serve exclusively.
  • Platform-managed hosts (Deno Deploy, Netlify Edge Functions, Supabase Edge Functions) never send your code SIGTERM. The built-in signal handling only matters when you run the Deno process yourself.
  • Use --allow-net (and others) explicitly, Deno's default-deny permissions are the point.

Request target and Host

Deno.serve builds request.url from the raw Host header and request line. The adapter checks it before your app runs: a Host that is not a plain host[:port] (userinfo, a backslash, an escape) is answered with 400, and a path that URL parsing would rewrite (\, .., %2e) is canonicalized first. The router and path-based guards such as except() therefore always see the same path. The scaffolded deno.json also sets "minimumDependencyAge": "P1D", the 24-hour cooldown the other templates get from their package manager.

See also

Edit this page on GitHub

Last updated