
Running Node.js applications in a cPanel environment is now easier than ever, thanks to the Node.js Selector feature typically provided by CloudLinux-based hosting providers. This article will guide you step-by-step on how to install, configure, and run your Node.js application directly from cPanel.
Prerequisites
Before starting this guide, please ensure you have met the following requirements:
-
cPanel Access: You have the login credentials to access your hosting control panel.
-
Hosting Support: Ensure your hosting provider has enabled the Setup Node.js App feature (CloudLinux).
-
Application Files: You already have your Node.js application files ready (including
package.jsonand a startup file likeapp.jsorserver.js).
Step-by-Step Guide to Running Node.js on cPanel
1. Login to cPanel
Open your web browser and navigate to your cPanel login page (usually via [yourdomain.com/cpanel](https://yourdomain.com/cpanel)). Enter your Username and Password to log in.
2. Locate "Setup Node.js App"
Scroll down the cPanel dashboard until you find the Software section. Click on the Setup Node.js App icon.
3. Create a New Application
On the Node.js Selector page, you will see a list of your existing applications. To add a new one:
-
Click the + Create Application button located in the top right corner of the screen.
4. Configure the Node.js Environment
You need to fill in several important details for your application:
-
Node.js version: Select the recommended version or the one most compatible with your application (e.g., 14.x.x, 16.x.x, or 18.x.x).
-
Application mode: Choose Production for a live website, or Development if you are still testing.
-
Application root: Enter the name of the folder where your application files will be stored (e.g.,
myappornodejs-app). This folder will be automatically created in your cPanel home directory, not insidepublic_html. -
Application URL: Select the domain or subdomain where this application will be accessible.
-
Application startup file: Enter the primary file name that should be executed first (e.g.,
app.js,server.js, orindex.js).
Once all fields are filled, click the Create button.
5. Upload Application Files
After the application framework is created by the system, the next step is to upload your source code:
-
Return to the main cPanel dashboard and open the File Manager.
-
Locate the folder that matches the Application root you specified in Step 4 (e.g.,
/home/username/myapp). -
Upload all your Node.js project files into this folder.
-
Important: You do not need to upload the
node_modulesfolder. You only need to upload thepackage.jsonfile along with your application scripts.
6. Install Dependencies (NPM Install)
Once the files are uploaded, your application needs its dependencies or modules to run.
-
Go back to the Setup Node.js App menu in cPanel.
-
Click the pencil icon (Edit) next to the application you just created.
-
Scroll down until you see the modules section. Click the Run NPM Install button.
-
Wait a few moments for the module installation process to finish. The system will read your
package.jsonfile and download all necessary dependencies.
7. Start the Application
After the NPM installation is complete:
-
Scroll to the top of the application configuration page.
-
Click the Restart button to apply the changes and ensure the application is running with the latest files.
Verification and Troubleshooting
To ensure your application is running smoothly, open a new browser tab and visit the Application URL you configured earlier.
Tips for Resolving Common Issues:
-
Error 503 (Service Unavailable): Double-check that your Application startup file is typed correctly. Also, ensure your code listens on the dynamic port provided by the environment, rather than a hardcoded port (use
process.env.PORT). -
Terminal Access: If you need to run specific commands, cPanel provides a Virtual Environment. At the top of the Node.js application edit page, there is a command you can copy (e.g.,
source /home/user/nodevenv/myapp/16/bin/activate). You can paste this command into the Terminal menu in cPanel to work within your app's environment.