How to host or deploy Express.js App in cPanel

You are here:
Estimated reading time: 1 min

To host or deploy an Express.js app on cPanel, follow these steps:

Step 1: Prepare Your Express.js App

  1. Ensure your Express.js app works locally.
  2. Install required dependencies using:
    bash
    
    npm install --production
    
  3. Modify package.json to include a start script if not already present:
    json
    
    "scripts": {
      "start": "node server.js"
    }
    

    (Replace server.js with your main entry file if different.)


Step 2: Upload Your Files to cPanel

  1. Log in to cPanel.
  2. Open File Manager and navigate to public_html or create a subdirectory like /expressapp.
  3. Upload your project files (excluding node_modules—install these later).

Step 3: Set Up Node.js in cPanel

  1. Go to “Setup Node.js App” under Software.
  2. Click Create Application and configure:
    • Node.js Version: Choose a supported version.
    • Application Mode: Production.
    • Application Root: The directory where you uploaded the app (e.g., /expressapp).
    • Application Startup File: Enter server.js (or your main file).
  3. Click Create.

Step 4: Install Dependencies

  1. In cPanel, open Terminal (or use SSH).
  2. Navigate to your app directory:
    bash
    
    cd ~/expressapp
    
  3. Run:
    bash
    
    npm install --production
    
  4. Restart the app from the Node.js selector in cPanel.

Step 5: Configure a Proxy for Public Access

  1. Open File Manager and navigate to public_html.
  2. Create or edit .htaccess and add:
    apache
    
    RewriteEngine On
    RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]
    

    (Replace 3000 with your app’s port from cPanel.)


Step 6: Test Your App

Visit your domain to check if the app runs successfully.


Optional: Use PM2 for Process Management

To ensure your app runs continuously:

  1. Install PM2:
    bash
    
    npm install -g pm2
    
  2. Start your app:
    bash
    
    pm2 start server.js
    
  3. Save the process:
    bash
    
    pm2 save
    pm2 startup
    

Troubleshooting

  • App Not Running? Check logs in cPanel’s Node.js App Manager or via:
    bash
    
    pm2 logs
    
  • Port Issues? cPanel assigns ports dynamically. Use the assigned port instead of 3000.
Was this article helpful?
Dislike 0

Author

Joshua

Web Hosting Geek Technical Support Staff G Online Sites