There was a problem loading the comments.

How to Deploy a Node.js Application on Linux Shared Hosting (cPanel + CloudLinux)

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

You can deploy Node.js applications on our Linux shared hosting using the Node.js Selector in cPanel, powered by CloudLinux and Phusion Passenger. Create a subdomain, set up the application, add your code, and run NPM install. The steps below cover a working Express deployment on a dedicated subdomain, plus fixes for the two most common setup errors.

What you need before you start

  • A cPanel account on one of our Linux shared hosting plans (the Setup Node.js App icon appears under the Software section).
  • Your application code, including a package.json file.
  • SSH access is optional but useful for git deployments and running npm ci. It is not required for the steps below.

Step 1: Create a subdomain for the application

We recommend giving each Node.js application its own subdomain. This keeps the application at the root path and avoids the most common routing error (covered in the FAQ below).

  1. In cPanel, go to Domains.
  2. Click Create A New Domain and enter a subdomain, for example node.example.com.
  3. Leave the document root at its default and save. Keep this folder empty; the Node.js Selector manages what is served here.

Step 2: Create the Node.js application

  1. In cPanel, open Setup Node.js App (Software section).
  2. Click Create Application.
  3. Set the fields as follows:
    • Node.js version: select the version your application requires. Choose the current LTS unless your app specifies otherwise.
    • Application mode: Production.
    • Application root: a folder name for your code, for example nodeapp. This creates /home/<username>/nodeapp.
    • Application URL: select the subdomain you created in Step 1 (node.example.com) and leave the path blank so the app serves at the root.
    • Application startup file: app.js.
  4. Click Create. cPanel builds the application and its isolated environment, and shows the command to enter that environment over SSH.

Step 3: Add your application files

Using the cPanel File Manager or SFTP, place these two files in your application root (/home/<username>/nodeapp).

package.json

{
  "name": "nodeapp",
  "version": "1.0.0",
  "main": "app.js",
  "dependencies": {
    "express": "^4.19.2"
  }
}

app.js

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Node OK - running ' + process.version);
});

// Do not hardcode a port. Passenger assigns it automatically.
app.listen();

Important: under the Node.js Selector, Phusion Passenger handles routing and serves your app over ports 80 and 443. Your app must not bind its own port. Use app.listen() with no argument, or read process.env.PORT. A hardcoded value such as app.listen(3000) is the most common reason an app fails to start.


Step 4: Install dependencies and start the app

  1. Return to Setup Node.js App and click Manage (the pencil icon) on your application.
  2. Click Run NPM Install. This installs the packages listed in package.json.
  3. Click Restart.

Step 5: Verify the deployment

Open your subdomain in a browser, or check it over SSH:

curl -I https://node.example.com/
curl https://node.example.com/

A working deployment returns 200 with the header x-powered-by: Express, and a body of Node OK - running v22... (or your selected version). The x-powered-by: Express header confirms the request reached your Node application.


Optional: create the app from the command line

If you have SSH access and prefer scripting, you can create the application in one command instead of using Steps 2:

cloudlinux-selector create --json --interpreter nodejs --version 22 \
  --app-root nodeapp --domain node.example.com --app-uri /

You can then place your files and run the install from within the application environment.


Frequently asked questions

After NPM install I see "check availability of application has failed". Is my app broken?

Usually no. After an operation such as NPM install, the Node.js Selector runs a check that compares the application response before and after. It reports a warning if the return code reads None or if the content type changes, for example from text/html to text/html; charset=utf-8. That change is expected: it means your real application has taken over from the placeholder, and Express adds the charset by default. Confirm your app is fine by loading the subdomain. If it returns your expected response with a 200 status, the warning is cosmetic and can be ignored.


I get "Cannot GET /myapp" or a 404 when I open my application.

This is Express returning its own 404, which means the request reached your app but no route matched the path. It happens when the application is served under a sub-path (for example /myapp) but the code only defines a root route such as app.get('/', ...). The simplest fix is to serve each application from its own subdomain, as described in Step 1, so the base path is / and standard routes work without adjustment. If you must run under a sub-path, mount your routes on an Express Router at that base path.


My application shows an error page or will not start. Where are the logs?

Check the application's stderr log, shown as the log path in the Setup Node.js App interface (commonly stderr.log in the application root, or under ~/logs). You can also run the app directly inside its environment over SSH to see the full error. The most common causes are a hardcoded port, a startup file name that does not match the actual entry file, and a dependency that did not install.


Which Node.js versions are available?

Multiple Node.js versions are available from the version dropdown, and each application can run its own version independently of other applications on the account. Select the version your app requires; use the current LTS if you have no specific requirement.


Do I need SSH access?

No. The full setup can be done from cPanel using Setup Node.js App and File Manager. SSH is helpful for git-based deployments, running npm ci, and viewing logs, but it is optional.


Share via
Did you find this article useful?  

Related Articles

Tags

© Softsys Hosting