Deployment
Deploying Node.js Apps with PM2 in Production
- Author :Liam K.
- Date :March 08, 2026
- Time :15 minutes
Step 1: Install Node.js LTS
bash
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs build-essential
node -v
npm -vStep 2: Install PM2 Globally
bash
sudo npm install -g pm2
pm2 -vStep 3: Prepare App and Dependencies
bash
cd /var/www/my-node-app
npm ci
cp .env.example .envStep 4: Create PM2 Ecosystem File
javascript
cat > ecosystem.config.js <<'EOF'
module.exports = {
apps: [
{
name: 'my-node-app',
script: 'dist/server.js',
instances: 'max',
exec_mode: 'cluster',
[...]Command truncated. Copy to view full command.
Step 5: Start and Inspect Process
bash
pm2 start ecosystem.config.js
pm2 ls
pm2 logs my-node-app --lines 100
pm2 monitStep 6: Enable Auto-Start on Reboot
bash
pm2 startup systemd -u $USER --hp /home/$USER
pm2 saveStep 7: Configure Log Rotation
bash
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 10M
pm2 set pm2-logrotate:retain 14
pm2 set pm2-logrotate:compress trueStep 8: Zero-Downtime Deploy Update
bash
git pull
npm ci
npm run build
pm2 reload ecosystem.config.js --update-envStep 9: Quick Health Checks
bash
curl -I http://127.0.0.1:3000/health
pm2 show my-node-app"PM2 gives you operational guardrails, but good deployment hygiene still depends on your release process."
Technical Author

Liam K.
System administrator and technical writer specializing in server infrastructure, security and deployment. Creating comprehensive guides to help you master server administration.
Related Guides
Ansible Dynamic Inventory for AWS at Scale
March 08, 2026
Ansible Role Testing with Molecule and CI Pipelines
March 08, 2026