GuideHow to Host a Node.js App on cPanel with Setup Node.js Apphostinq.com

How to Host a Node.js App on cPanel with Setup Node.js App

Many developers assume a Node.js app needs a VPS. For a small API, a webhook receiver, a Telegram or Slack bot backend or an Express site, a cPanel account with the Setup Node.js App tool is often enough. You do not install Node.js yourself, you do not manage a process manager, and the app is served through the same domain and SSL certificate as the rest of your site.

This guide walks through the whole process: preparing the code, creating the application in cPanel, installing packages with npm, setting environment variables, restarting, and reading logs when something goes wrong.

What you need before you start

  • A hosting plan with Node.js enabled. On CloudLinux servers the tool appears in cPanel under Software as "Setup Node.js App". If you do not see it, your plan does not include it.
  • Your app's code with a package.json file that lists every dependency.
  • A startup file, usually app.js or server.js, that creates the HTTP server.
  • Optional but useful: SSH access or the cPanel Terminal, so you can run npm commands yourself. Our cPanel user guide for beginners explains where these tools are.

How Node.js runs on cPanel

On a VPS you would start the app with node app.js or PM2 and put a reverse proxy in front of it. On cPanel the web server does that job for you. The Node.js Selector from CloudLinux uses Phusion Passenger, and on LiteSpeed servers LiteSpeed provides a compatible handler that reads the same configuration.

Three consequences matter for your code:

  • The port is ignored. Your app still calls listen(), but the server connects to it through an internal socket. Whatever port you pass has no effect, and you cannot reach the app on that port from outside.
  • The process is started on demand. The first request starts the app. After a quiet period it may be stopped and started again on the next request, so do not rely on in-memory timers for scheduled jobs.
  • CommonJS is the safe default. Passenger loads the startup file with require(). If your project uses ES modules, use a small wrapper file (shown below).

Step 1: Prepare your app

A minimal Express app that works on cPanel looks like this:

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

app.get('/', (req, res) => {
  res.send('Hello from Node.js on cPanel');
});

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Listening on ${port}`);
});

Keep the listen() call. Passenger waits for it to know the app is ready. The same code still runs on your laptop on port 3000.

If your package.json contains "type": "module", create a wrapper named app_wrapper.cjs and use it as the startup file:

(() => import('./app.js'))();

Do not upload your local node_modules folder. The Node.js Selector keeps packages in a separate virtual environment and links them into the app folder, and it refuses to install if a real node_modules folder already exists there.

Step 2: Create the application in cPanel

  1. Log in to cPanel and open Setup Node.js App.
  2. Click Create Application.
  3. Node.js version: choose the newest LTS line your server offers. Node.js 20 reached end of life in April 2026, so prefer 22 or 24.
  4. Application mode: choose Production for a live site. This sets NODE_ENV for you.
  5. Application root: a folder in your home directory, for example myapp. Keep it outside public_html so your source code and secrets cannot be downloaded through the browser.
  6. Application URL: pick the domain or subdomain, and optionally a path such as api. A subdomain like api.example.com keeps the app separate from your main website.
  7. Application startup file: app.js, server.js or your wrapper file.
  8. Passenger log file: a path such as /home/USER/logs/myapp.log, so errors are written somewhere you can read them.
  9. Click Create.

cPanel now writes a block of Passenger directives into the .htaccess file of the domain's document root, between comments that mention CLOUDLINUX PASSENGER CONFIGURATION. Do not edit or remove that block by hand. If the domain already served a WordPress site, the Node.js app now answers on that URL instead, which is another reason to use a subdomain.

Step 3: Upload your code

Upload the project files into the application root with File Manager, SFTP or Git. A typical folder looks like this:

/home/USER/myapp/
  app.js
  package.json
  package-lock.json
  routes/
  views/

Commit package-lock.json so the server installs the same versions you tested locally.

Step 4: Install dependencies with npm

Return to Setup Node.js App and click the edit icon next to your application. cPanel detects package.json and shows a Run NPM Install button. Click it and wait for the success message.

For more control, use SSH or the Terminal. The application page shows a command that activates the app's environment. It looks like this, with your username, folder and Node.js version:

source /home/USER/nodevenv/myapp/24/bin/activate && cd /home/USER/myapp
npm ci --omit=dev
node -v

npm ci installs exactly what the lock file lists. Front-end builds (React, Vue, Vite, Next.js) need a lot of memory, so it is usually better to run the build on your computer or in CI and upload only the output.

Step 5: Set environment variables

API keys, database passwords and tokens belong in environment variables, not in your code. On the application page, find the Environment variables section, click Add Variable, enter a name and value, then click Save.

Your code reads them as usual:

const dbUrl = process.env.DATABASE_URL;
const botToken = process.env.BOT_TOKEN;

A .env file loaded with a package such as dotenv also works, because the application root is outside the public web folder. Never place a .env file inside public_html.

Step 6: Restart after every change

Node.js keeps your code in memory, so uploaded changes do nothing until the app restarts. Click Restart on the application page after you change code, packages or variables.

From SSH you can trigger the same restart, which is handy in deploy scripts:

mkdir -p /home/USER/myapp/tmp
touch /home/USER/myapp/tmp/restart.txt

The server notices the new timestamp and restarts the app on the next request.

Logs and troubleshooting

When the app does not start, the browser usually shows a 503 error or a Passenger error page. Check the Passenger log file you set in Step 2. On LiteSpeed servers, anything your app writes to stderr also lands in stderr.log in the application root. Our article on 502 and 503 errors explains what those codes mean in general.

SymptomLikely causeWhat to do
503 right after creating the appStartup file name is wrong or crashes on loadRun node app.js in the activated environment and read the error
Error mentioning node_modules on npm installA real node_modules folder was uploadedDelete or rename it, then run Run NPM Install again
ERR_REQUIRE_ESMThe project uses ES modulesUse the .cjs wrapper as the startup file
Cannot find moduleDependency missing from package.jsonAdd it to package.json, install again, restart
Changes do not appearApp was not restartedClick Restart or touch tmp/restart.txt

What shared hosting is not built for

CloudLinux gives each account its own CPU, memory and process limits, which protects your app from neighbors and neighbors from your app. It also means some workloads fit better elsewhere:

  • Background workers that must run every second of the day, such as queue consumers or scrapers.
  • Apps that need their own open port, a database engine you install yourself, or system packages.
  • Heavy real-time traffic with thousands of open connections.

Scheduled tasks are still possible: run a script with a cron job instead of a timer inside the web process. If you outgrow these limits, our article on when it is time to move to a VPS lists the usual signs.

Frequently asked questions

Do I need PM2 or forever on cPanel?

No. Passenger starts, stops and restarts the app for you. A process started separately with PM2 would not receive web traffic, and long-running background processes may be stopped by the account's limits.

Can I run a Next.js app this way?

Often, yes. Build the project on your computer with the output: 'standalone' option, upload the result and use the generated server.js as the startup file. Large apps may need more memory than a shared account provides.

Why is the first request slow after a quiet period?

An idle app can be stopped to free memory. The next visitor's request starts it again, which adds a short delay. Steady traffic keeps it running.

Do WebSockets work?

On LiteSpeed servers, WebSocket upgrade requests are passed to the Node.js app automatically. Use wss:// on HTTPS sites. For a large number of permanent connections, a VPS is the better fit.

Can I host several Node.js apps in one account?

Yes. Create one application per domain, subdomain or path, each with its own root folder and Node.js version. All of them share your account's resource limits.

Hostinq.com shared hosting runs cPanel on CloudLinux and LiteSpeed, with Setup Node.js App available from the Economic X1 plan upward (Ultra Economic does not include Node.js). You can compare the plans on the shared hosting page, and if your app needs root access or always-on workers, look at our KVM VPS plans.

Share: