Setting Up a Node.js Application in cPanel
Many cPanel hosting accounts include a Node.js Selector that allows you to deploy and manage Node.js applications without requiring root access or manual server configuration. This tool handles version management, dependency installation, and application startup.
Prerequisites
- A hosting plan that supports the Node.js Selector (check with your hosting provider).
- Your Node.js application code ready to deploy.
- An application entry point file (commonly
app.jsorserver.js).
Creating a Node.js Application
- Log in to cPanel.
- Navigate to the Software section.
- Click on Setup Node.js App.
- Click Create Application.
- Configure the application:
| Setting | Description |
|---|---|
| Node.js version | Select the desired version (e.g., 18.x, 20.x) |
| Application mode | Choose Development or Production |
| Application root | The directory containing your app files (e.g., myapp) |
| Application URL | The URL path where the app will be accessible |
| Application startup file | The entry point (e.g., app.js) |
| Passenger log file | Optional log file path for debugging |
- Click Create to set up the application.
cPanel will create the application environment and display a success message with your application’s details.
Installing Dependencies
After creating the application:
- Go back to Setup Node.js App in cPanel.
- Click the pencil icon (edit) next to your application.
- Scroll down to find the Run NPM Install button and click it.
This reads your package.json file and installs all listed dependencies into a virtual environment managed by cPanel.
Alternatively, copy the command shown at the top of the application page and run it in the cPanel Terminal:
source /home/username/nodevenv/myapp/18/bin/activate
cd ~/myapp
npm install
Managing Your Application
From the Node.js Selector dashboard, you can:
- Start/Stop/Restart the application using the action buttons.
- Change Node.js versions by editing the application settings.
- Switch between Development and Production modes.
- View logs to troubleshoot issues.
Application Structure
A typical Node.js application in cPanel should have:
myapp/
├── app.js # Entry point
├── package.json # Dependencies and scripts
├── package-lock.json # Dependency lock file
├── node_modules/ # Installed packages (created by npm install)
└── public/ # Static files (if applicable)
Environment Variables
To set environment variables for your Node.js application:
- Edit your application in the Node.js Selector.
- Scroll to the Environment variables section.
- Add key-value pairs as needed (e.g.,
NODE_ENV=production,DB_HOST=localhost). - Save and restart the application.
Troubleshooting
- Application not loading: Check the startup file path and ensure all dependencies are installed.
- 502 or 503 errors: Review the Passenger log file for error messages. The application may have crashed.
- Port issues: cPanel uses Phusion Passenger to proxy requests — do not hardcode a port. Instead, use the
PORTenvironment variable or let Passenger handle it. - Module not found errors: Run NPM Install again from the Node.js Selector to reinstall dependencies.
- Version compatibility: If your app requires a specific Node.js version, ensure it is available in the selector. Contact your hosting provider if the needed version is not listed.
Important Notes
- Node.js applications on cPanel shared hosting run through Phusion Passenger, not as standalone processes.
- Resource limits on shared hosting may restrict CPU and memory usage for your application.
- For production applications with high traffic, consider a VPS or dedicated server for better performance.