Manual vs Automated Deployment
Even if you use CI/CD in production, understanding manual deployment helps you debug pipeline failures.
Prerequisites
Before deploying, ensure the server has:- Node.js installed (via NVM)
- PM2 installed globally
- Nginx installed and configured
- Your .env variables ready to set on the server
- SSH access to the server
Complete First Deployment
1
SSH into the server
2
Navigate to the apps directory
3
Clone the repository
4
Install production dependencies only
5
Create the .env file
6
Start with PM2
7
Save PM2 process list
8
Verify the application is running
Updating the Application
After pushing code changes to GitHub, update the server:pm2 restart vs pm2 reload
Rollback Procedure
If a deployment causes errors:Common Deployment Errors and Fixes
Deployment Checklist
Full Deployment Script
Save this asdeploy.sh and run it on the server:
Key Terms
Common Mistakes
Pushing the .env file to Git
Pushing the .env file to Git
Never commit .env to your repository. Copy it to the server securely using
scp or by pasting values into a file created with nano .env directly on the server.Using npm install --save in production
Using npm install --save in production
Running npm install without —production installs devDependencies (jest, nodemon, eslint) on the production server. Use
npm install --production or npm ci --only=production to keep the server lean.Not running npm install after pulling
Not running npm install after pulling
If your pull added new packages to package.json, they won’t be available until you run npm install. Always include npm install in your update procedure.
Using pm2 restart instead of pm2 reload
Using pm2 restart instead of pm2 reload
pm2 restart causes a brief downtime. pm2 reload performs a rolling restart with zero downtime. Always use pm2 reload for production code updates.