Node.js runs server-side JavaScript. How you deploy it depends on whether you’re on shared hosting (cPanel) or a VPS.

On Shared Hosting (cPanel)

GoZen Host shared plans support Node.js through cPanel’s built-in Node.js selector.

Step 1: Create the Application

  1. Log into cPanel
  2. Go to SoftwareSetup Node.js App
  3. Click Create Application
  4. Configure:
SettingValue
Node.js versionPick the latest LTS (e.g., 20.x or 22.x)
Application modeProduction
Application rootmyapp (folder inside your home directory)
Application URLYour domain or subdomain
Application startup fileapp.js or server.js
  1. Click Create

Step 2: Upload Your Code

Upload your project files to the Application root directory. Use File Manager or SFTP.

Your project should include a valid package.json.

Step 3: Install Dependencies

In the Node.js App screen:

  1. Click Run NPM Install. This installs your package.json dependencies
  2. Click Restart to start the app

Environment Variables

Add environment variables in the Node.js App interface:

  1. Scroll to Environment variables
  2. Click Add Variable
  3. Enter the key/value pairs (e.g., NODE_ENV = production)
  4. Click Save then Restart

On a VPS

On a VPS, you have full control. Use PM2 to keep your app running.

Step 1: Install Node.js

Step 2: Deploy Your App

  # Clone or upload your project
cd /var/www
git clone https://github.com/you/your-app.git myapp
cd myapp

# Install dependencies
npm install --production
  

Step 3: Install and Configure PM2

PM2 keeps your app alive, restarts it on crash, and handles logs.

  # Install PM2 globally
sudo npm install -g pm2

# Start your app
pm2 start app.js --name "myapp"

# Save the process list so it restarts on reboot
pm2 save
pm2 startup
  

Step 4: Set Up Nginx as a Reverse Proxy

  server {
    listen 80;
    server_name yourdomain.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_cache_bypass $http_upgrade;
    }
}
  
  # Test and reload Nginx
sudo nginx -t
sudo systemctl reload nginx
  

PM2 Cheat Sheet

CommandWhat it does
pm2 listShow all running apps
pm2 logs myappView real-time logs
pm2 restart myappRestart the app
pm2 stop myappStop the app
pm2 delete myappRemove from PM2
pm2 monitInteractive monitoring dashboard

Troubleshooting

ProblemFix
App not starting on cPanelCheck the startup file path. Make sure package.json exists in the app root
“Module not found” errorsRun NPM Install again from the Node.js App screen
502 Bad Gateway (VPS)Your Node app isn’t running. Check pm2 list and pm2 logs
Port already in useAnother process is on port 3000. Use lsof -i :3000 to find it
App crashes on rebootRun pm2 save and pm2 startup to persist your process list

What to Do Next

Last updated 05 Apr 2026, 00:00 +0200. history

Was this page helpful?