Running Node.js and NPM on cPanel depends on your hosting provider’s configuration. Some providers offer built-in Node.js support (often via CloudLinux), while others may require you to use SSH access. Below is a simple guide explaining common ways to use NPM within a cPanel environment.
1. Check If Your Hosting Supports Node.js
- Not all cPanel hosting packages include Node.js support. Log in to your cPanel and look for a feature called Setup Node.js App, or ask your hosting provider if Node.js is supported.
2. Option A: Using the “Setup Node.js App” Feature (If Available)
- Log into cPanel: Access your cPanel dashboard, usually via
yourdomain.com/cpanel
. - Find “Setup Node.js App”: Under the Software or Advanced section, look for an icon or link named Setup Node.js App.
- Create a New Application:
- Click Create Application or + Create.
- Select the Node.js version you want to use.
- Specify the application path (for example,
~/my_node_app
). - Optionally, set your
app.js
orserver.js
file as the main file.
- Install Dependencies:
- Some hosts have a built-in field to run commands directly (like
npm install
) in this interface. - Type
npm install
in the command field to install yourpackage.json
dependencies.
- Some hosts have a built-in field to run commands directly (like
- Start the App: After installation, click Run App or Restart to launch your Node.js application. This process should also run NPM as needed.
3. Option B: Using cPanel’s Terminal or SSH (If Node.js App Feature Is Not Available)
- Enable Terminal/SSH Access:
- Log in to cPanel and check if there is a Terminal feature under the Advanced section.
- If not available, request SSH access from your hosting provider.
- Open Terminal: If you have the Terminal icon, click it to open a browser-based SSH session. Otherwise, use an SSH client like PuTTY or Terminal on macOS/Linux to log in with your cPanel username and password.
- Navigate to Your Project Directory:
cd ~/public_html/my_node_app
Adjust the path to match where you uploaded your Node.js project.
- Install Dependencies with NPM:
npm install
This command will install all modules listed in
package.json
. - Run NPM Scripts:
npm run build npm run start
Use
npm run <scriptName>
to execute any custom scripts defined in yourpackage.json
. - Keep Your App Running (Optional):
- For persistent apps, consider using a process manager like
pm2
if your host allows it. npm install pm2 -g
thenpm2 start app.js
- For persistent apps, consider using a process manager like
Important: Not all shared hosting environments fully support Node.js or persistent processes. Check your plan’s documentation or ask your hosting provider for details on resource limits and whether background Node.js processes are permitted.
4. Uploading Your Project Files
- You can upload your Node.js project via cPanel’s File Manager or an FTP client.
- Ensure that
package.json
is included in the uploaded files, so thatnpm install
can fetch your dependencies.
5. Conclusion
To run NPM in cPanel, you generally need Node.js support through a feature like “Setup Node.js App” or via SSH/Terminal. Once you have the right environment, you can install dependencies (npm install
) and run scripts (npm run ...
) just like on a local machine. Always check with your hosting provider to confirm available Node.js versions and resource limits.