How do you achieve zero-downtime deployment?
Use pm2 reload (not restart) in cluster mode. PM2 reloads workers one at a time old workers finish their current requests while new workers start with the new code. No connections are dropped. For multiple servers, use a load balancer and update one server at a time.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Node.js Deployment Interview Questions AWS, Docker, CI/CD, and Production
Provision a server (AWS EC2), install Node.js/PM2/Nginx, clone code and npm install, configure .env with production secrets, start with PM2, configure Nginx as reverse proxy, add SSL with Let's Encrypt, and set up CI/CD for automated deployments.
PM2 is a process manager: keeps the app running (survives SSH disconnect), auto-restarts on crash, supports cluster mode (multiple instances per CPU core), captures logs, and starts on system boot. Use pm2 start, pm2 save, and pm2 startup.
Create a Dockerfile: FROM node:20-alpine, WORKDIR /app, COPY package*.json, RUN npm ci --production, COPY ., EXPOSE 3000, CMD ['node', 'src/server.js']. Create docker-compose.yml with build, ports, env_file, and restart: unless-stopped. Use .dockerignore to exclude node_modules and .env.
Still have questions?
Browse all our FAQs or reach out to our support team
