Prerequisites
- A Kazepute Breeze with at least 1 GB RAM
- SSH access configured
- Domain name (optional but recommended)
Step 1: Install Node.js
# Using NodeSource (recommended for production)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Verify
node --version
npm --version
Step 2: Deploy Your Application
# Create app directory
sudo mkdir -p /var/www/myapp
sudo chown deploy:deploy /var/www/myapp
# Clone your repo
git clone git@github.com:you/myapp.git /var/www/myapp
cd /var/www/myapp
# Install dependencies
npm ci --production
# Build (if needed)
npm run build
Step 3: Process Manager (PM2)
# Install PM2 globally
sudo npm install -g pm2
# Start your app
pm2 start server.js --name myapp
# Or with ecosystem file
pm2 start ecosystem.config.js
Ecosystem File
// ecosystem.config.js
module.exports = {
apps: [{
name: 'myapp',
script: 'server.js',
instances: 'max', // Use all CPU cores
exec_mode: 'cluster',
env: {
NODE_ENV: 'production',
PORT: 3000,
},
max_memory_restart: '300M',
error_file: '/var/log/myapp/error.log',
out_file: '/var/log/myapp/output.log',
merge_logs: true,
}]
};
# Auto-start on reboot
pm2 startup
pm2 save
Step 4: Nginx Reverse Proxy
server {
listen 80;
server_name myapp.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
Step 5: SSL Certificate
sudo certbot --nginx -d myapp.example.com
Monitoring
# App status
pm2 status
# Live logs
pm2 logs myapp
# Metrics
pm2 monit
Deployment Updates
cd /var/www/myapp
git pull
npm ci --production
npm run build
pm2 restart myapp
| PM2 Command | Action |
|---|---|
pm2 start |
Start app |
pm2 stop myapp |
Stop app |
pm2 restart myapp |
Restart app |
pm2 reload myapp |
Zero-downtime restart |
pm2 delete myapp |
Remove from PM2 |
pm2 logs |
View logs |
Tip Use
pm2 reloadinstead ofpm2 restartfor zero-downtime deployments in cluster mode.