Skip to content
Blog

How to Deploy a Node.js App on cPanel Hosting

You don't need your own server to run a Node.js app. Here is how to deploy one with cPanel's Setup Node.js App, and when a VPS is the better home.

Lines of program code on a screen
On this page

Node.js is often associated with cloud platforms and containers, but many apps run perfectly well on ordinary cPanel hosting. If your hosting includes the Setup Node.js App tool, you can deploy an Express API, a NestJS backend or a Next.js site from the control panel, without managing a server. This guide walks through the steps and explains where the limits are.

How Node.js runs on cPanel

On cPanel hosting, your app is started by Phusion Passenger, which sits behind the web server. When a request arrives, Passenger starts your app if it is not running, passes the request to it and restarts it if it crashes. You do not run node server.js yourself or keep a process alive with a tool such as PM2. That makes deployment simple, but it also means the app may be paused after a quiet period, so the first request after a pause is slightly slower.

Before you start

  • Check which Node.js versions your host offers. Production apps should run a long-term support release.
  • Make sure your app listens on the port it is given through the PORT environment variable, or uses Passenger's defaults; do not hard-code a port.
  • Have a clear startup file, such as app.js or server.js.
  • Put your code in a Git repository if you can; it makes updates much easier.

Step 1: Create the application

Open Setup Node.js App in cPanel and choose Create Application. Pick the Node.js version, set the mode to Production, choose a folder for the code (outside public_html is best), choose the web address the app will answer on, and enter the startup file name. Save, and cPanel creates the folder and a virtual environment for the app.

Step 2: Upload the code

Use cPanel's Git Version Control to clone your repository into the app folder, or upload files over SFTP. Leave the node_modules folder out: dependencies are installed on the server so they match its platform.

Step 3: Install dependencies

Back in Setup Node.js App, open your application and click Run NPM Install. It reads your package.json and installs what the app needs. If you prefer SSH, the app page shows a command that switches your session into the app's Node.js environment, so node and npm use the right version.

Step 4: Add environment variables

Database passwords, API keys and other secrets belong in environment variables, set on the app page in cPanel. They are available to your app as process.env values and never need to be committed to your repository.

Step 5: Restart and test

Click Restart, then open the web address. A simple health route that returns the Node.js version, such as /health, is a quick way to confirm that the right version is running. Free SSL covers the domain or subdomain the app answers on.

Frameworks

Express, Fastify, Koa and Hono

These run as they are: set the startup file to the file that creates and exports or starts the server.

NestJS

Build the project, then point the startup file at the compiled entry file in the build folder, usually dist/main.js.

Next.js

Run next build, then start the app from a small custom server file that uses Next's request handler. Busy Next.js sites with many server-rendered pages are better suited to a VPS.

React, Vue and Vite front ends

A static build does not need Node.js on the server at all. Upload the built files to ordinary web hosting and save the cost.

Databases

Create a MySQL database and user in cPanel and connect from Node.js with a driver such as mysql2, using localhost as the host. For MongoDB, use a hosted service, or run it yourself on a VPS.

Updating the app

Pull the latest code with Git Version Control or upload changed files, run NPM Install if dependencies changed, and restart the app. Keep the previous release in Git so you can roll back quickly if something breaks.

Logs and monitoring

Write your app's errors to standard error and keep a simple log of requests that fail. On cPanel, Passenger writes start-up errors to a log file in the app folder, which is the first place to look when the app will not start. Add an external uptime check that calls your health route every few minutes, so you hear about a problem before your users do.

When to move to a VPS

cPanel hosting is a good fit for websites, APIs, payment callbacks and bots. Choose a Cloud VPS when your app needs:

  • Processes that must run all the time, such as queue workers or scheduled jobs every few seconds.
  • Many long-lived connections, such as WebSockets for chat or live dashboards.
  • Docker, custom system packages or a database other than MySQL.
  • Consistently high traffic that needs dedicated CPU and memory.

On a VPS you control the process manager (PM2 or systemd), the reverse proxy and the whole stack. Our Node.js hosting page compares both options and includes a starter kit you can deploy in minutes.

Troubleshooting

  • "Cannot find module": run NPM Install again and check the module is in dependencies, not only devDependencies.
  • Blank page or 503: check the app's error log in its folder, and confirm the startup file name.
  • Wrong Node.js version in SSH: run the environment command shown on the app page first.
  • Changes not showing: restart the app after every deployment.

Frequently asked questions

Can I run more than one Node.js app?

Yes, within your plan's limits. Each app has its own folder, version and web address.

Do I need SSH?

No. Everything can be done in cPanel, although SSH is useful if you prefer the command line.

Why is the first request sometimes slow?

Passenger can pause an idle app to save resources. The first request after a pause starts it again. For constant availability, use a VPS.

Can I use TypeScript?

Yes. Compile it to JavaScript and point the startup file at the compiled output.

Is HTTPS included?

Yes. Free SSL covers the domain or subdomain your app runs on.

Written by

telaHosting

Writes for telaHosting on the topics our customers ask about most.

Join the conversation

What is your perspective?

Share a useful experience or ask a question. Keep the discussion constructive and avoid sharing private customer information.

Leave a comment

Your email address is kept private.

New comments are reviewed before publication to keep the discussion useful.