Your Node.js service now has complete PM2 deployment support with the following additions:
ecosystem.config.js- PM2 configuration filedeploy-pm2.sh- Automated deployment scriptpm2-manager.sh- Process management scriptPM2_DEPLOYMENT.md- Comprehensive documentation.env.example- Environment variables templatelogs/directory with.gitignoreand.gitkeep
package.json- Added PM2 dependency and scriptsserver/index.js- Added/healthendpoint for monitoring.gitignore- Added PM2 and environment file patterns
pm2@^5.3.0- Process manager for Node.js
| Command | Action |
|---|---|
npm run pm2:start |
Start with PM2 |
npm run pm2:stop |
Stop application |
npm run pm2:restart |
Restart application |
npm run pm2:reload |
Zero-downtime reload |
npm run pm2:status |
Show process status |
npm run pm2:logs |
View logs |
npm run pm2:monit |
Open monitoring dashboard |
./deploy-pm2.sh |
Automated deployment |
./pm2-manager.sh [command] |
Advanced process management |
./deploy-pm2.sh# Copy environment file
cp .env.example .env
# Start with PM2
npm run pm2:start
# Check status
npm run pm2:status- Auto-restart on crashes
- Memory monitoring (restarts at 1GB)
- Structured logging with rotation
- Health checks via
/healthendpoint - Graceful shutdown handling
- Environment-specific configurations
- Real-time process monitoring
- Memory and CPU usage tracking
- Log aggregation and viewing
- Health check endpoint at
http://localhost:5001/health
- Start/stop/restart commands
- Zero-downtime reloads
- Cluster mode support (configurable)
- Automatic recovery from failures
Your application will be available at:
- Main API:
http://localhost:5001/api - Health Check:
http://localhost:5001/health
-
Configure Environment:
cp .env.example .env # Edit .env with your specific settings -
Deploy Application:
./deploy-pm2.sh
-
Monitor Application:
npm run pm2:monit
-
View Logs:
npm run pm2:logs
- Never commit
.envfiles to version control - Use proper firewall rules for port access
- Consider using a reverse proxy (nginx) for SSL/TLS
- Run with non-root user in production
For detailed information, see PM2_DEPLOYMENT.md which includes:
- Advanced configuration options
- Troubleshooting guide
- Production deployment best practices
- Performance tuning tips
- Integration with CI/CD
Your Node.js service is now ready for production deployment with PM2! π