2.8 KiB
2.8 KiB
⚡ PM2 Quick Start - LuckyChit
Get your LuckyChit app running in production in 5 minutes!
🚀 Super Quick Deployment
1. Install PM2 (if not installed)
npm install -g pm2
2. Setup Environment
cd backend
cp .env.example .env
# Edit .env with production credentials
nano .env
3. Deploy with One Command
cd backend
chmod +x deploy.sh
./deploy.sh production
Done! ✅
📱 What You Get
- ✅ Backend running on port 3000
- ✅ Auto-restart on crashes
- ✅ Load balanced across all CPU cores
- ✅ Daily scheduled restart at 3 AM
- ✅ Automated payment reminders (9 AM IST)
- ✅ Comprehensive logging
🎯 Essential Commands
# Status
pm2 list
# Monitor
pm2 monit
# Logs
pm2 logs luckychit-backend
# Restart
pm2 restart luckychit-backend
# Stop
pm2 stop luckychit-backend
🔄 Updates (Zero Downtime)
git pull origin main
cd backend
npm install
pm2 reload luckychit-backend
🤖 Auto-Start on Server Reboot
One-time setup:
pm2 startup
# Run the command it outputs (copy/paste it)
pm2 save
Now your app automatically restarts after server reboot!
🔍 Troubleshooting
⚠️ bcrypt Error (Most Common)
Error: invalid ELF header or ERR_DLOPEN_FAILED
Quick Fix (Run on Linux server):
cd backend
chmod +x fix-bcrypt.sh
./fix-bcrypt.sh
Or manually:
cd backend
rm -rf node_modules package-lock.json
npm install
pm2 restart luckychit-api
Cause: node_modules installed on Windows, deployed to Linux. Native modules must be rebuilt on the target OS.
App not starting?
pm2 logs luckychit-backend --lines 100
Database connection failed?
Check .env file has correct credentials:
cat backend/.env
Port already in use?
# Find what's using port 3000
lsof -i :3000
# Kill it
kill -9 <PID>
# Restart
pm2 restart luckychit-backend
More help? See DEPLOYMENT_TROUBLESHOOTING.md
📊 Monitoring URLs
- Backend Health Check:
http://localhost:3000/api/health(add this endpoint) - API Documentation:
http://localhost:3000/api/docs - Share Endpoint:
http://localhost:3000/api/share - Notifications:
http://localhost:3000/api/notifications
🎯 Production Checklist
- PM2 installed (
pm2 --version) .envfile configured- Database running and accessible
- App started with PM2 (
pm2 listshows running) - Auto-start configured (
pm2 startup+pm2 save) - Test API endpoints
- Setup nginx reverse proxy (optional)
- Setup SSL certificate (recommended)
📚 Need More Details?
See the complete guide: PM2_PRODUCTION_GUIDE.md
Your LuckyChit backend is now running in production! 🎉