Node.js Production

Essential Git commands for everyday development — clone, commit, push, pull, and branch management.

Last Updated: May 2, 2026

Node.js production patterns: clustering, graceful shutdown, health checks, structured logging with pino, memory management, and Docker optimization.

Clustering & Process Management

ApproachDetails
Built-in clusterconst cluster = require('cluster'); cluster.fork()
PM2pm2 start app.js -i max
Worker threadsnew Worker('./heavy-task.js')

Graceful Shutdown

SIGTERM handler
process.on('SIGTERM', () => server.close(...))
Kubernetes
Set terminationGracePeriodSeconds to match Node timeout.

Structured Logging with Pino

pino()
Fastest Node logger — JSON output, child loggers for request context.
pino-pretty
Development only — never in production.

Docker Optimization

TechniqueBenefit
node:22-alpineSmallest image (~50MB)
Multi-stage buildsCopy only production artifacts
.dockerignoreExclude node_modules, .git
Pro Tip: Set up /health endpoint verifying DB and cache — Kubernetes uses this for readiness probes.