Skip to Content
Senri

Deployment

Remove devtools() from production builds. NODE_ENV. Notes for each runtime

src/index.ts
import {  } from "@senrijs/senri";
import {  } from "@senrijs/senri/serve";

const  = ();   // no dev: devtools() in production builds
.("/", () => "Hello!");

await ();
NODE_ENV=production PORT=8080 node src/index.ts

Remove devtools()

There are two ways to handle development mode in production. Removing it from production builds is the safest.

WayResult
Do not pass dev: devtools()The development code is not bundled. Only the core remains (about 7 KB after gzip)
Keep dev: devtools() and set NODE_ENV=productiondevtools() does nothing, so no development pages appear. But bundlers that put everything in one file (such as wrangler for Workers) still include the code

If you forget NODE_ENV, development output still goes only to requests to localhost (Using devtools()). Still, remove it or set NODE_ENV=production.

Behind a reverse proxy on the same machine

If the proxy forwards Host: localhost as is, requests look like requests to localhost. In production, set NODE_ENV=production or remove devtools().

Environment variables

VariableUsed by
NODE_ENVWith production, devtools() does nothing
PORTThe port of serve() (when there is no port option)

Many hosting services set PORT for you, and serve() reads it.

Notes for each runtime

  • Node.js: node:http limits the time to receive a whole request to 5 minutes by default (requestTimeout). Sending a large file over a slow connection can end in 408 midway
  • Bun, Deno and Node.js: on SIGTERM, the server waits for in-flight requests before stopping (Graceful shutdown)
  • Cloudflare Workers: deploy with wrangler deploy. devtools() only works with wrangler dev, but it is still bundled, so remove it (Cloudflare Workers)
  • Containers such as Docker: the client does not look like localhost, so the development dashboard cannot be opened. When developing in a container, set NODE_ENV=development

Monitoring

On this page