Prerequisites
Before installing Node.js, make sure you have:
- SSH access to your VPS
- Node.js installed
- PM2 installed (process manager)
Step 1: Install Node.js
ssh hxroot@YOUR_SERVER_IP -p 22
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
Step 2: Install PM2 Globally
npm install -g pm2
Step 3: Upload Your Node.js Application
scp -r /local/node-app/ admin@YOUR_SERVER_IP:/home/admin/web/example.com/public_html/
Step 4: Install Dependencies
cd /home/admin/web/example.com/public_html
npm install
Step 5: Start App with PM2
pm2 start app.js --name "myapp"
pm2 save
pm2 startup
Step 6: Configure Nginx as Reverse Proxy
In HestiaCP, edit domain → Advanced Options:
Add proxy configuration to route traffic to Node.js port (e.g., 3000).
Or manually edit Nginx config:
nano /home/admin/conf/web/nginx.example.com.conf
Add inside server block:
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_cache_bypass $http_upgrade;
}
Step 7: Restart Nginx
systemctl restart nginx
Step 8: Open Firewall Port (If Direct Access Needed)
ufw allow 3000/tcp
PM2 Useful Commands
pm2 list # List all apps
pm2 logs myapp # View logs
pm2 restart myapp # Restart app
pm2 stop myapp # Stop app
pm2 delete myapp # Delete app
pm2 monit # Monitor resources
✅ Node.js application has been deployed successfully!