Koskamo

Production performance and reliability best practices

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Set NODE_ENV to production: Express then caches view templates, caches CSS files generated from CSS extensions, and generates less verbose error messages — tests indicate this alone can improve performance by a factor of three. Use gzip compression via the compression middleware, but implement it at a reverse proxy level for high-traffic sites. Avoid synchronous functions in production; the --trace-sync-io flag prints a warning and stack trace whenever your app uses a synchronous API (for pre-production checks, not production). console.log() and console.error() are synchronous when the destination is a terminal or file; use the debug module with the DEBUG environment variable for debugging and a logging library like Pino for app activity. Handle exceptions with try-catch for synchronous code and with promises; do not listen for uncaughtException, because process state becomes unreliable, and do not use the deprecated domains module. Offload CPU-intensive work to worker threads through a fixed pool (for example with piscina) rather than a new worker per request. Run the latest Node.js LTS, ensure restarts with a process manager plus systemd (Restart=always and Environment=NODE_ENV=production in the unit file), and run a cluster with one instance per CPU core — instances do not share memory, so store state in a datastore like Redis. Cache request results with Varnish or Nginx, use a load balancer, and run Express behind a reverse proxy such as Nginx or HAProxy. Scope: Express. Reviewed October 4, 2026.

Source and provenance

Original source
expressjs.com
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.