PM2 Deployment on Vultr
PM2 is a production‑grade process manager for Node.js applications that enables persistent services, automatic restarts, and clustering for better CPU utilization. Deploying on a Vultr Cloud Compute instance combines fast provisioning with flexible scaling, while Nginx adds reverse‑proxy capabilities and SSL termination for secure traffic.
Core Installation Steps
This section outlines the essential commands to provision the server, install runtime dependencies, and prepare the environment for a resilient Node.js service.
Provision a Vultr Node.js Marketplace Server
From the Vultr dashboard select a region, choose the NodeJS Marketplace image (pre‑installed Node.js and npm), pick an appropriate size, and launch the instance.
Set Up a Sample Express Application
Create a project directory, initialize npm, and install Express:
mkdir ~/express-demo cd ~/express-demo npm init -y npm install express
Create index.js with a simple route that returns Hello World, greetings from Vultr and test it with node index.js on port 3000.
Install PM2 and Launch in Cluster Mode
Globally install PM2, start the app with four clustered instances, and save the process list for automatic resurrection after reboot:
sudo npm install -g pm2 pm2 start ~/express-demo/index.js -i 4 --name express-demo pm2 save
PM2 now monitors each instance and restarts them on failure.
Configure Nginx as a Reverse Proxy
Install Nginx, create a site configuration pointing to the local Node.js port, enable the site, and reload the service:
sudo apt update && sudo apt install -y nginx sudo nano /etc/nginx/sites-available/express-demo.conf
Paste the following (replace example.com with your domain):
server {
listen 80
server_name example.com www.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
}
}Enable and test the configuration:
sudo ln -s /etc/nginx/sites-available/express-demo.conf /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
Allow HTTP traffic through the firewall (sudo ufw allow 80/tcp).
Secure the Site with Let’s Encrypt SSL
Install Certbot via snap, request a certificate for both the root and www domains, and verify automatic renewal:
sudo snap install --classic certbot sudo certbot --nginx -d example.com -d www.example.com sudo certbot renew --dry-run
Open HTTPS in the firewall (sudo ufw allow 443/tcp) and confirm the site loads via https://example.com.
Scaling and Monitoring with PM2
Adjust instance count on demand without downtime using pm2 scale. For example, reduce to two instances:
pm2 scale express-demo 2
Or increase to five instances:
pm2 scale express-demo 5
Reload processes gracefully (pm2 reload all) and view logs (pm2 logs) for real‑time monitoring.
Advanced Resource Planning
Understanding future data‑center architecture helps anticipate scaling needs when multiple services share the same hardware, ensuring that PM2 clusters remain performant under load.