Node.js Deployment
Package release
Production builds should install dependencies deterministically from your lockfile and exclude development-only packages such as test runners and linters. Pin your Node LTS version in package.json (engines.node) or your container base image so runtime behavior matches staging:
# Install exact lockfile versions without devDependencies
npm ci --omit=dev
# Build TypeScript or assets, then start with production env
NODE_ENV=production node dist/app.js
- Set a clear
"start"script inpackage.jsonthat runs the compiled output. - Bundle or copy only the runtime files your container or host needs.
- Keep build artifacts (
dist/) separate from authored source control.
Configuration
Use environment variables for secrets, database URLs, and environment-specific flagsānever commit .env files or credentials into Git. Validate all required environment variables when the process boots so misconfigured deployments fail immediately with a clear log message rather than crashing on the first user request.
Cloud checklist
Before routing live traffic to a new Node service, verify startup, observability, and graceful shutdown (handling SIGINT / SIGTERM so in-flight requests finish before the process exits):
- Confirm the app starts locally with
NODE_ENV=productionand the exact production command. - Verify structured JSON logs, a
/healthendpoint, and dynamicprocess.env.PORTbinding. - Document and test rollback steps (redeploying the previous immutable image or commit) before the first release.
Practice
Write a short deployment runbook for one Node service covering its start command, required environment variables, health-check path, and rollback procedure.