Your Node.js service now supports both full-stack and backend-only deployment using PM2.
Runs both React frontend and Node.js backend concurrently:
# Quick deployment
./deploy-pm2.sh fullstack
# Or using npm scripts
npm run pm2:start:fullstackRuns only the Node.js backend server:
# Quick deployment
./deploy-pm2.sh backend
# Or using npm scripts
npm run pm2:start:backend| File | Purpose |
|---|---|
ecosystem.fullstack.config.js |
Full-stack deployment (frontend + backend) |
ecosystem.backend.config.js |
Backend-only deployment |
ecosystem.config.js |
Main config with both app definitions |
npm run pm2:start:fullstack # Start full-stack app
npm run pm2:start:backend # Start backend only
npm run pm2:start # Start both (default config)
npm run pm2:stop # Stop all processes
npm run pm2:restart # Restart all processes
npm run pm2:status # Show process status
npm run pm2:logs # View logs
npm run pm2:monit # Open monitoring dashboard./deploy-pm2.sh [fullstack|backend] # Automated deployment
./pm2-manager.sh [command] [fullstack|backend] # Advanced management- Frontend (React): http://localhost:3000
- Backend API: http://localhost:5001/api
- Health Check: http://localhost:5001/health
- Backend API: http://localhost:5001/api
- Health Check: http://localhost:5001/health
# Deploy both frontend and backend
./deploy-pm2.sh fullstack
# Check status
npm run pm2:status
# View logs
npm run pm2:logs
# Monitor processes
npm run pm2:monit# Deploy only the backend
./deploy-pm2.sh backend
# Check health
curl http://localhost:5001/health
# View backend logs
pm2 logs backend-only# Advanced management with specific deployment type
./pm2-manager.sh deploy fullstack
./pm2-manager.sh health fullstack
./pm2-manager.sh restart backend- Process Name:
fullstack-dev - Command:
npm run dev(runs concurrently) - Ports: 3000 (frontend), 5001 (backend)
- Process Name:
backend-only - Command:
node server/index.js - Port: 5001
- Uses
npm run devcommand - Runs both frontend and backend
- Higher memory limit (2GB)
- Longer timeout for startup
- Combined logging
- Direct Node.js execution
- Health check monitoring
- Lower memory usage (1GB)
- Production-ready settings
fullstack-dev.log- Full-stack app logsbackend-only.log- Backend-only app logs*-out.log- Standard output*-error.log- Error logs
# All logs
npm run pm2:logs
# Specific process logs
pm2 logs fullstack-dev
pm2 logs backend-only
# Follow logs in real-time
pm2 logs --lines 100curl http://localhost:5001/health{
"uptime": 123.456,
"timestamp": "2025-09-05T10:30:00.000Z",
"status": "OK",
"pid": 12345,
"memory": {
"rss": 45678912,
"heapTotal": 12345678,
"heapUsed": 8765432
},
"environment": "development",
"version": "2.0.0"
}-
Port conflicts:
# Check what's using the ports lsof -i :3000 lsof -i :5001 -
Client dependencies missing:
cd client && npm install
-
PM2 permission issues:
sudo chown -R $(whoami) ~/.pm2
-
Process not starting:
# Check PM2 logs pm2 logs # Check configuration node -e "console.log(require('./ecosystem.fullstack.config.js'))"
# Start full-stack with hot reload
./deploy-pm2.sh fullstack
# Make changes to code
# Both frontend and backend will auto-reload# Deploy backend for production
NODE_ENV=production ./deploy-pm2.sh backend
# Or with PM2 environment
pm2 start ecosystem.backend.config.js --env production-
Memory Optimization:
- Full-stack: 2GB limit (handles both processes)
- Backend-only: 1GB limit (single process)
-
Log Management:
# Install log rotation pm2 install pm2-logrotate # Configure rotation pm2 set pm2-logrotate:max_size 10M pm2 set pm2-logrotate:retain 30
-
Monitoring:
# Real-time monitoring pm2 monit # Process details pm2 show fullstack-dev pm2 show backend-only
- Environment variables are loaded from
.envfile - Health check endpoint exposes system information
- Use reverse proxy (nginx) for production SSL/TLS
- Firewall configuration for port access
-
Configure Environment:
cp .env.example .env # Edit .env with your settings -
Choose Deployment Type:
- Full-stack for development
- Backend-only for API server
-
Set Up Monitoring:
npm run pm2:monit
-
Production Setup:
- Use nginx reverse proxy
- Configure SSL certificates
- Set up proper logging
- Configure firewall rules
Your application is now ready for both development and production deployment! 🎉