Node.js Deployment Interview Questions AWS, Docker, CI/CD, and Production
Master Node.js deployment interview questions AWS EC2, Docker, CI/CD pipelines, PM2, Nginx, and production best practices.
Node.js Deployment Interview Questions
Deployment knowledge is essential for full-stack developers. Here are the most common questions.
Q1: How Do You Deploy a Node.js App to Production?
Answer:
- Provision a server (AWS EC2, DigitalOcean, etc.)
- Install Node.js, PM2, Nginx
- Clone the code and
npm install - Configure .env with production secrets
- Start with PM2
pm2 start server.js --name app - Configure Nginx as a reverse proxy
- Add SSL with Let's Encrypt
- Set up CI/CD for automated deployments
Q2: What Is PM2 and Why Use It?
Answer: PM2 is a process manager for Node.js:
- Keeps app running Survives SSH disconnection
- Auto-restart Restarts on crash
- Cluster mode Multiple instances per CPU core
- Logs Captures stdout and stderr
- Startup script Starts on system boot
pm2 start server.js --name myapp -i max # Cluster mode pm2 save pm2 startup # Start on boot
Q3: What Is the Role of Nginx in Node.js Deployment?
Answer:
- Reverse proxy Routes port 80/443 to Node.js on 3000
- SSL termination Handles HTTPS certificates
- Static files Serves React/Vue build files
- Load balancing Distributes traffic across instances
- Gzip compression Reduces response sizes
- Rate limiting Protects against abuse
Q4: How Do You Dockerize a Node.js App?
Answer:
# Dockerfile FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --production COPY . . EXPOSE 3000 CMD ["node", "src/server.js"]
# docker-compose.yml services: api: build: . ports: - "3000:3000" env_file: - .env.production restart: unless-stopped
Q5: How Do You Set Up CI/CD for Node.js?
Answer:
# .github/workflows/deploy.yml name: Deploy on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' - run: npm ci - run: npm test - name: Deploy uses: appleboy/ssh-action@v1 with: host: ${{ secrets.EC2_HOST }} key: ${{ secrets.EC2_KEY }} script: | cd /app git pull npm ci pm2 reload myapp
Q6: How Do You Handle Zero-Downtime Deployment?
Answer:
# PM2 reload (not restart) zero downtime pm2 reload myapp # In cluster mode, PM2 reloads workers one at a time # Old workers finish requests, new workers handle new ones
With multiple instances:
# Update one at a time pm2 reload myapp
Q7: What Are Production Best Practices?
Answer:
- Use environment variables Never hardcode secrets
- Set NODE_ENV=production Enables optimizations
- Use a process manager PM2 for auto-restart
- Enable clustering Use all CPU cores
- Set up logging Winston + Morgan
- Monitor PM2 monit, CloudWatch, Sentry
- Use HTTPS Let's Encrypt + Nginx
- Rate limit Prevent abuse
- Backup database Regular automated backups
- Health checks /api/health endpoint
The Takeaway
Deployment questions cover: production deployment steps (EC2, PM2, Nginx, SSL), PM2 (process manager keeps app running, auto-restart, cluster mode), Nginx role (reverse proxy, SSL, static files, load balancing, compression), Docker (Dockerfile with node:20-alpine, docker-compose), CI/CD (GitHub Actions with SSH deploy), zero-downtime (pm2 reload in cluster mode), and production best practices (env vars, NODE_ENV, logging, monitoring, HTTPS, rate limiting, backups, health checks).
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.
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.
Use environment variables (never hardcode secrets), set NODE_ENV=production, use PM2 for process management, enable clustering (all CPU cores), set up logging (Winston), monitor (Sentry, CloudWatch), use HTTPS (Let's Encrypt), rate limit, backup database, add health check endpoint, and set up CI/CD.
Ready to master Node.js completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master Node.js
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

