How to host or deploy Express.js App in cPanel
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
- Ensure your Express.js app works locally.
- Install required dependencies using:
- Modify
package.json
to include a start script if not already present:(Replace
server.js
with your main entry file if different.)
Step 2: Upload Your Files to cPanel
- Log in to cPanel.
- Open File Manager and navigate to
public_html
or create a subdirectory like/expressapp
. - Upload your project files (excluding
node_modules
—install these later).
Step 3: Set Up Node.js in cPanel
- Go to “Setup Node.js App” under Software.
- 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).
- Click Create.
Step 4: Install Dependencies
- In cPanel, open Terminal (or use SSH).
- Navigate to your app directory:
- Run:
- Restart the app from the Node.js selector in cPanel.
Step 5: Configure a Proxy for Public Access
- Open File Manager and navigate to
public_html
. - Create or edit
.htaccess
and add:(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:
- Install PM2:
- Start your app:
- Save the process:
Troubleshooting
- App Not Running? Check logs in cPanel’s Node.js App Manager or via:
- Port Issues? cPanel assigns ports dynamically. Use the assigned port instead of 3000.