Skip to content
Deploying apps5 min read

How to run a Node.js app on hosting

Short answer

To run Node.js on cPanel hosting, open Setup Node.js App and create an application with a Node version, application root, URL and startup file such as app.js. Install dependencies with Run NPM Install, or npm install after entering the virtual environment, add environment variables and restart. The app must listen on process.env.PORT, because Phusion Passenger starts it.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Before you start
  2. Steps
  3. Troubleshooting
  4. On ArabyHost

On cPanel hosting you don’t run node app.js yourself and leave it going. You register the app in Setup Node.js App (CloudLinux’s Node.js selector), and Phusion Passenger starts it, connects it to your site’s URL and restarts it when needed. All your code has to do is listen on the port Passenger hands it.

Before you start

  • A plan with Setup Node.js App and SSH, such as the AI/Developer plans.
  • An app that runs on Node.js 20 or 24, with a package.json listing its dependencies.
  • A domain or subdomain for the app; a subdomain such as app.example.com is simplest.

Steps

1. Prepare the app

The one hard rule is to listen on process.env.PORT. A minimal Express app.js:

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}`));

Don’t start two servers in the same code, and don’t hard-code a port.

2. Upload the code outside public_html

Put the project in a folder such as /home/USER/myapp, as a ZIP through File Manager or cloned from GitHub (see deploy from GitHub). Don’t upload node_modules: the Node.js selector keeps packages inside its virtual environment and puts a symlink with that name in your app folder.

3. Create the app in Setup Node.js App

In cPanel, open Setup Node.js App, click Create Application and fill in:

Field Value
Node.js version 20 or 24, to match your project
Application mode Production
Application root myapp (path from your home folder)
Application URL The domain or subdomain, optionally with a path
Application startup file app.js or your entry file
Passenger log file For example /home/USER/logs/myapp.log

Click Create. The tool builds the virtual environment and writes Passenger settings into the domain’s .htaccess, between the CLOUDLINUX PASSENGER CONFIGURATION BEGIN and END lines. Don’t delete that block.

4. Add environment variables

On the app’s page, under Environment variables, click Add Variable for each secret or setting, such as DATABASE_URL and API_KEY, then Save. Your code reads them from process.env. NODE_ENV follows the Application mode.

5. Install dependencies

The easiest way is the Run NPM Install button on the app’s page, which appears once the tool finds package.json. Over SSH, copy the command shown at the top of the page to enter the virtual environment; it looks like this:

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

Use npm install if you have no package-lock.json. The 20 in the path is the Node version you selected.

6. Build, if your project needs it

For TypeScript or bundled projects, run this inside the same environment:

npm run build

Or use Run JS script on the app’s page to run a script from package.json. If the build is heavy on memory, build locally and upload the output. For Next.js see deploy Next.js.

7. Restart and test

Click Restart on the app’s page after any code or variable change, or over SSH:

mkdir -p tmp && touch tmp/restart.txt

Then open the app’s URL in a browser.

8. Read the logs

Anything the app writes with console.log and console.error goes to the Passenger log file you set. Read the end of it over SSH:

tail -n 50 /home/USER/logs/myapp.log

9. Always-on bots and workers

Passenger runs the app in response to requests and may stop it when idle. A bot or worker that must always run is better started as a separate process, kept alive by a cron job every minute, with flock so two copies never run at once:

* * * * * cd /home/USER/myapp && /usr/bin/flock -n /home/USER/worker.lock /home/USER/nodevenv/myapp/20/bin/node /home/USER/myapp/worker.js >> /home/USER/logs/worker.log 2>&1

If the process is running, flock exits immediately; if it has died, cron starts it again within a minute. A full example is in run a Discord bot.

Troubleshooting

  • “Web application could not be started”: the app crashed during startup. Open the log and see Passenger app error.
  • A message asking to store node_modules in the virtual environment: there’s a real node_modules folder in the app root. Delete it and click Run NPM Install.
  • “Cannot find module”: dependencies weren’t installed in the environment, or the package sits in devDependencies. See Cannot find module.
  • EADDRINUSE: the code listens on a fixed port or starts a second server. See EADDRINUSE.
  • “require() of ES Module” error: the project uses "type": "module". Create a tiny startup file named app.cjs containing import('./server.js'); and set it as the startup file.
  • The old site shows instead of the app: files such as index.html or index.php are still in the domain’s root. Move them out, or give the app its own subdomain.

On ArabyHost

Node.js apps run on ArabyHost AI/Developer plans, with Node.js 20 and 24 through the CloudLinux selector and Phusion Passenger, SSH jailed in CageFS, Git, and background workers kept alive with cron. You can deploy from GitHub, by ZIP, or from Claude and Cursor through Araby MCP, and run Claude Code and Codex over SSH. Resources are shared with per-account limits, and there’s no Docker, root access or GPU. If the log isn’t clear, the Araby AI assistant reads the error log and explains the fix.

FAQ

Do I need PM2 to run Node.js on cPanel?

Not for web apps. Phusion Passenger starts the app when requests arrive and restarts it if it crashes. Bots and workers that must run all the time without web requests run as a separate process kept alive by a cron job.

Where should I put my Node.js app's files?

In their own folder outside public_html, such as /home/USER/myapp, which you then enter as the Application root. Passenger connects the site URL to the app for you.

Why is the first request slow after a quiet period?

Passenger may stop an idle app to save resources and start it again on the next request. Keep startup light and defer heavy connections until they're needed.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.