How to host a Node.js app on Shared Hosting (cPanel)

Namecheap Shared Hosting lets you run Node.js applications directly from cPanel, so you can deploy standard apps without using SSH. The list of supported Node.js versions changes from time to time, so check the article for the current options.

This guide explains how to deploy your application in cPanel and fix common errors:


How to deploy a Node.js app in cPanel

To deploy a Node.js app on Shared Hosting, first create the application environment in cPanel, then upload your project files, install dependencies, and restart the app.

Because shared servers host multiple accounts on a single machine, each Node.js application runs in its own isolated virtual environment. Once you configure that environment in cPanel, the server starts and manages the application for you.


Step 1: Create the application in Setup Node.js App

Create your Node.js runtime environment in cPanel before uploading any project files. Follow the steps described in the How to work with the Setup Node.js App pluginarticle.


Step 2: Upload your project files

Next, add your application files to the Application root folder you defined in Step 1. Use File Manager to upload them manually, or use Git Version Control if you plan to update your application regularly.


Step 3: Check your app settings

Verify that your settings in Setup Node.js App match your uploaded files and Shared Hosting requirements before installing packages:

  • Startup file: Confirm that the Application startup file in Setup Node.js App matches the exact file path in File Manager (e.g., app.js).
  • Port configuration: Shared Hosting assigns an internal port automatically and routes your domain traffic to it. Check your startup file to make sure it uses process.env.PORT instead of a hardcoded port like 3000 or 8080. Hardcoding a port can prevent the app from loading.
  • Environment variables: If your app relies on a local .env file for API keys and/or database credentials, add those values in Setup Node.js App.

    Info: Setting Application mode to “Production” handles NODE_ENV=production automatically.


Step 4: Run NPM Install

To install your project dependencies, ensure that the package.json file sits inside the Application root folder:

And follow these steps:

  1. Go back to Setup Node.js App and click the pencil icon (Edit) next to your application to edit it.
  2. Click Run NPM Install:

cPanel installs all listed packages into your app's virtual environment.

Note: If your project does not have package.json or it uses an incompatible Node.js version, cPanel won't detect the configuration file:

See the section below for troubleshooting steps if the “Run NPM Install” button does not appear.

If you need to install additional modules via the command line, enter the application's virtual environment via SSH. Refer to this page if you're not sure how to enter the virtual environment.


Step 5: Start and test the app

Click Restart in Setup Node.js App and open your Application URL in a browser to verify the live response.

Tip: Whenever you upload new files/edit environment variables later, restart the app so the server loads the changes.


Common Node.js errors in cPanel and how to fix them

Some issues may arise when you deploy your application or upload it from your local device. Find the error/symptom below for the steps to resolve it.


App not starting (500/503 error)

Check that your code listens to process.env.PORT and that your Application startup file matches the exact filename inside your Application root folder, as described in Step 3: Check your app settings.

If the settings look correct, open stderr.log inside the Application root folder in File Manager to read the exact error message.


Changes not showing up

Restart the application via Setup Node.js App after every change, such as editing a file or updating an environment variable.

Node.js keeps your application code cached in memory once it starts, and making changes does not automatically reload the running process.


Errors after running Run NPM Install

If Run NPM Install fails with an error message, check the detailed npm logs inside /home/USER/.npm/_logs/ (replace USER with your cPanel username).

Tip: Because .npm is a hidden folder, open Settings in the top right of File Manager and enable Show Hidden Files (dotfiles) to view it.


App feels slow/hits timeout errors

Slow responses, timeouts, or intermittent 503 errors usually mean your app is hitting Shared Hosting CPU/RAM limits. To fix that:

  1. Switch Application mode to “Production” in Setup Node.js App so your framework enables caching and reduces overhead. Click Save, then click Restart.
  2. Check Resource Usage in cPanel for limit faults.
  3. If heavy traffic or unoptimized usage continues to hit resource limits after tuning, consider moving the app to a more advanced hosting plan, such as VPS.


Run NPM Install button does not appear

This button stays hidden when cPanel cannot locate/read the package.json file inside the Application root folder.

Check the file first:

  • If the file is missing, upload your project's package.json to the Application root folder (or create it in File Manager). For a brand-new project, you can also run npm init -y in the application's virtual environment to generate a default package.json.
  • If the file exists, make sure it is named exactly “package.json” and is located directly in the Application root folder.

If the file is present but the button still doesn't appear, try a different Node.js version.

Why this happens: Setup Node.js App reads package.json using the Node.js environment you selected. If that version is not compatible with the file's contents or the packages it lists, the environment cannot process the file. The system then behaves as if the file does not exist, and the button is hidden.


Error: Cannot find module

This error means Node.js is trying to load a package that is missing from your server environment. This usually happens for one of the following reasons:

  • Dependencies were not installed: You uploaded your code/edited package.json without clicking Run NPM Install in cPanel.
  • package.json is in a subfolder: Extracting an archive often creates an extra folder (like /nodeapp/my-project/), so cPanel cannot detect package.json inside your Application root.
  • The package is under devDependencies: In “Production” mode (NODE_ENV=production), npm skips devDependencies during install. If your app runs in “Development” mode, npm installs them automatically, so this will not cause the error.


Index of / page

When you set up an application for a domain, the following code is added to the .htaccess file of the domain's Document Root (for subfolders, it will be located in the corresponding subfolder):

If the code in .htaccess is missing, requests will fail, and an Index of / page will be displayed at the app URL.

A quick way to fix that is to stop the app in Setup Node.js App, then start it again so the system re-adds the .htaccess rule.


Can't acquire lock for app

This error appears when a background process is using your application's .lock file. It usually happens after starting a long-running script through Run JS Script, since cPanel has no button to stop that script once it runs in the background.

To fix the issue, stop the active process that is holding your app's .lock file via cPanel Terminal.

For detailed steps, see Managing active processes on Shared and Reseller hosting.


npm: command not found

This error appears when you run npm commands in cPanel Terminal without entering the application's virtual environment first.

Refer to this page to access the virtual environment.


Package fails to install with a GCC error

A GCC error occurs when an npm package tries to compile from source on the server and hits a compiler restriction or version mismatch:

  • If the error says ‘failed: Permission denied’, contact our Support team to have the GCC compiler enabled for your account.
  • If it says ‘failed: No such file or directory’, the package version is not compatible with the compiler on the server. Install an earlier version of the package or switch to one that ships with precompiled binaries.


FAQ

Updated
Viewed
50 times

Need help? We're always here for you.

notmyip