StarDomain

How to Deploy Node.js App on Shared Hosting

How to Deploy Node.js App on Shared Hosting

{{COMPANY_NAME}} shared hosting supports Node.js applications through CloudLinux. Here is how to deploy your Node.js app without needing a VPS.

Prerequisites

  • A {{COMPANY_NAME}} cPanel or DirectAdmin hosting account (any plan).
  • Your Node.js application code.
  • SSH access (available on all plans).

Method 1: cPanel Node.js Application Manager

Step 1: Access the Node.js Setup

  1. Log in to cPanel.
  2. Go to Software > Setup Node.js App.
  3. Click Create Application.

Step 2: Configure the Application

  • Node.js Version: select the version your app requires (14.x, 16.x, 18.x, 20.x).
  • Application Mode: Development or Production.
  • Application Root: the folder containing your app (e.g., `myapp`).
  • Application URL: the domain/path for your app.
  • Application Startup File: your entry point (e.g., `app.js or server.js`).

Step 3: Upload Your Code

  1. Use File Manager or FTP to upload your application files to the Application Root folder.
  2. Or use SSH with Git:
bash
cd ~/myapp
git clone https://github.com/you/your-repo.git .

Step 4: Install Dependencies

  1. In the Node.js App Manager, click Run NPM Install or use the virtual environment command shown.
  2. Or via SSH:
bash
cd ~/myapp
source /home/username/nodevenv/myapp/18/bin/activate
npm install

Step 5: Start the App

  1. In the Node.js App Manager, click Start or Restart.
  2. Visit your application URL to verify it works.

[screenshot: cPanel Node.js Application Manager]

Method 2: DirectAdmin Node.js

  1. Log in to DirectAdmin.
  2. Go to Node.js setup (under Extra Features or Advanced).
  3. Create a new application.
  4. Set the version, root directory, and startup file.
  5. Upload code and install dependencies.
  6. Start the application.

Environment Variables

Set environment variables in the Node.js Application Manager:

  1. Click your application.
  2. Find Environment Variables section.
  3. Add key-value pairs (e.g., `NODE_ENV=production, PORT=3000`).
  4. Click Save and restart.

Troubleshooting

Application Not Starting

  • Check the startup file name is correct.
  • Review error logs (shown in the Application Manager).
  • Verify all dependencies installed correctly.

"502 Bad Gateway"

  • The Node.js process may have crashed. Check logs.
  • Restart the application from the Application Manager.

Port Issues

  • Do NOT bind to a specific port. The hosting proxy handles routing.
  • Use the port provided by the environment or bind to the socket.

Need help? Contact our support team at {{SUPPORT_URL}}/client/support.