Node.js theorytheory 0/50 · 0%
Tooling · hard

46. Deploying a Node service

Process managers, health checks and zero-downtime patterns.

In production, a Node process should never be run bare in a terminal: a process manager (PM2, systemd, or a container orchestrator) restarts it on crash, manages logs, and can run multiple instances. A health-check endpoint lets load balancers and orchestrators detect an unhealthy instance and stop routing traffic to it.

js
app.get("/health", (req, res) => {
  const healthy = db.isConnected() && rpcIsReachable;
  res.status(healthy ? 200 : 503).json({ healthy });
});
json
{ "scripts": { "start": "node dist/index.js" } }

Zero-downtime deploys start new instances, wait for them to pass health checks, shift traffic over, then gracefully shut down the old instances — never simply killing the old process and starting the new one, which would drop in-flight requests.

Check your understanding

  1. 1. Why not run a production Node process bare in a terminal session?

  2. 2. What is a health-check endpoint used for?

  3. 3. What does a zero-downtime deploy avoid?