Hands-on guide series
Node.js in Production: A Hands-On Guide
A six-part, hands-on guide to running Node.js in production on a single VPS: install the LTS and serve behind nginx, run it under systemd, configure it with environment secrets, cluster across cores, deploy with zero downtime, and add health checks and metrics. Every command tested on a live Ubuntu 24.04 server.
What you will build
Security is layers, not a switch. Each part closes a different category of attack, from the automated sweep that finds a brand-new server, to the day one gets in anyway. Read them in order, or jump to what you need.
- 1
Install Node.js and Run a Real AppSee the destination first, then install the Node.js LTS on a bare slice, write a small Express node.js app, and serve it live behind nginx and in a browser.9 min - 2
Run Node.js Under systemdTurn the node.js app into a systemd service that starts on boot and restarts on failure. Kill the process by hand and watch systemd bring it back with a new PID.6 min - 3
Environment, Config and SecretsConfigure a node.js app through the environment and keep node.js secrets in a 600 file only the service user can read, with NODE_ENV set to production.6 min - 4
Clustering Across CPU CoresUse the node.js cluster module to run one worker per CPU core so both cores serve traffic. See the worker PIDs and prove different workers answer different requests.6 min - 5
Zero-Downtime Reload and Graceful ShutdownHandle SIGTERM for a graceful shutdown that drains in-flight requests, then roll a restart through two instances behind nginx with every request still 200.6 min - 6
Health Checks, Logging and MetricsAdd a node.js health check endpoint, structured JSON logs in journald, and a metrics endpoint exposing memory and event-loop delay, all reachable through nginx.6 min