Skip to content

Latest commit

Β 

History

History
123 lines (95 loc) Β· 2.98 KB

File metadata and controls

123 lines (95 loc) Β· 2.98 KB

PM2 Deployment Summary

πŸš€ What's Been Added

Your Node.js service now has complete PM2 deployment support with the following additions:

πŸ“ New Files Created:

  • ecosystem.config.js - PM2 configuration file
  • deploy-pm2.sh - Automated deployment script
  • pm2-manager.sh - Process management script
  • PM2_DEPLOYMENT.md - Comprehensive documentation
  • .env.example - Environment variables template
  • logs/ directory with .gitignore and .gitkeep

πŸ”§ Modified Files:

  • package.json - Added PM2 dependency and scripts
  • server/index.js - Added /health endpoint for monitoring
  • .gitignore - Added PM2 and environment file patterns

πŸ“¦ New Dependencies:

  • pm2@^5.3.0 - Process manager for Node.js

πŸ› οΈ Available Commands

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

πŸš€ Quick Start

1. Simple Deployment:

./deploy-pm2.sh

2. Manual Steps:

# Copy environment file
cp .env.example .env

# Start with PM2
npm run pm2:start

# Check status
npm run pm2:status

πŸ” Key Features

βœ… Production Ready:

  • Auto-restart on crashes
  • Memory monitoring (restarts at 1GB)
  • Structured logging with rotation
  • Health checks via /health endpoint
  • Graceful shutdown handling
  • Environment-specific configurations

πŸ“Š Monitoring:

  • Real-time process monitoring
  • Memory and CPU usage tracking
  • Log aggregation and viewing
  • Health check endpoint at http://localhost:5001/health

πŸ”§ Process Management:

  • Start/stop/restart commands
  • Zero-downtime reloads
  • Cluster mode support (configurable)
  • Automatic recovery from failures

🌐 Endpoints

Your application will be available at:

  • Main API: http://localhost:5001/api
  • Health Check: http://localhost:5001/health

πŸ“ Next Steps

  1. Configure Environment:

    cp .env.example .env
    # Edit .env with your specific settings
  2. Deploy Application:

    ./deploy-pm2.sh
  3. Monitor Application:

    npm run pm2:monit
  4. View Logs:

    npm run pm2:logs

πŸ”’ Security Notes

  • Never commit .env files 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

πŸ“š Documentation

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! πŸŽ‰