EN · $ USD
Developer and Application Servers

How to Run a Node.js App in cPanel

7 min read Updated: Sunucu Atlas technical team

In short

To run a Node.js app in cPanel, you create an application in the Setup Node.js App tool by choosing the Node.js version, app folder, URL and startup file. Then you install the dependencies from package.json with Run NPM Install, add environment variables and start it with Restart. For long-running background jobs or projects that need Docker, a server with root access is a better fit.

In this guide
  1. What Is Setup Node.js App?
  2. 1. Prepare Your App
  3. 2. Create the App in cPanel
  4. 3. Upload Your Files and Run npm install
  5. 4. Define Environment Variables
  6. Connecting to a MySQL Database
  7. Reading Logs
  8. 5. Start and Restart the App
  9. Practical Performance Tips
  10. Common Errors
  11. Shared Hosting or a Coolify Server?
  12. Next Step

To run a Node.js app in cPanel, you use the Setup Node.js App tool: pick the Node.js version, set the app folder and the URL it will be served from, point to the startup file, install dependencies with Run NPM Install, and start the app. The web server forwards incoming requests to your app and manages the process for you. For Express, Fastify or a simple API, this method is fast and sufficient. In this guide we'll set it up step by step, then make clear when shared hosting isn't enough.

What Is Setup Node.js App?

Setup Node.js App is the cPanel interface for managing Node.js applications. For each app it creates a separate virtual environment with the Node.js version you choose, keeps the node_modules folder in that environment, and connects your app to the web through an application server. You don't need tools like pm2 or forever to keep your app running; process management happens in this layer.

To use this tool, your hosting plan must include the Node.js application manager. Sunucu Atlas Laravel hosting plans include the Node.js and Python application manager, Terminal/SSH access and Git together in cPanel.

1. Prepare Your App

Don't hardcode the port your app listens on. Use the port provided by the environment, and fall back to a default value locally:

// app.js
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Merhaba, uygulama çalışıyor!');
});

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

Your project root must contain a package.json file listing its dependencies. Don't upload the node_modules folder to the server; dependencies will be installed on the server, inside the virtual environment.

2. Create the App in cPanel

  1. In cPanel, open the Setup Node.js App tool under Software.
  2. Click the Create Application button.
  3. Node.js version: choose the LTS version your project supports. If package.json has an engines field, follow it.
  4. Application mode: choose Production for a live site. This means NODE_ENV=production.
  5. Application root: the folder where the files will live, for example nodeapp. Keep this folder outside public_html.
  6. Application URL: the domain and optional path the app will be served from. Using a subdomain (e.g. api.alanadiniz.com) avoids conflicts with your main site; add the subdomain first under Domains in cPanel.
  7. Application startup file: the name of your entry file, for example app.js or server.js.
  8. Click Create to create the app.

cPanel creates a sample startup file in the application root and starts the app. If you see a test page when you open the URL, the connection is ready.

3. Upload Your Files and Run npm install

Copy your project files to the nodeapp folder with File Manager, FTP or Git. Then install dependencies in one of two ways.

From the interface

In the Setup Node.js App list, click the pencil icon next to the app. Once package.json is detected, the Run NPM Install button becomes active. Clicking it installs the dependencies into the virtual environment.

From the terminal

At the top of the app's edit screen, you'll see a copyable command for entering the virtual environment. It looks like this:

source /home/kullaniciadi/nodevenv/nodeapp/20/bin/activate && cd /home/kullaniciadi/nodeapp
npm install --omit=dev
node -v

The version number in the path depends on the Node.js version you selected; copy the command from your own screen. If you're new to the terminal, see the cPanel SSH access and Terminal guide.

Important: the app folder must not contain its own node_modules folder. The tool keeps that folder in the virtual environment and creates a symbolic link to it in the application root. If there's a manually uploaded node_modules folder, delete it and run the install again.

4. Define Environment Variables

Instead of hardcoding secrets like database passwords or API keys, pass them as environment variables. On the app's edit screen, add them under Environment variables with Add Variable:

NameExample value
DB_HOSTlocalhost
DB_NAMEkullaniciadi_nodeapp
DB_USERkullaniciadi_dbuser
DB_PASSA strong password
JWT_SECRETA long random string

In your code, you access these values as process.env.DB_HOST. After saving changes, you need to restart the app. You can also use a .env file with the dotenv package; in that case, make sure the file isn't in the web root.

Connecting to a MySQL Database

To connect from Node.js to a MySQL database you created in cPanel, the mysql2 package is a popular, trouble-free choice. Because the database is on the same server, the host is localhost. cPanel prefixes database and user names with your account name; put these full names in your environment variables.

// db.js
const mysql = require('mysql2/promise');

const pool = mysql.createPool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME,
  connectionLimit: 5
});

module.exports = pool;

Keeping the connection pool small matters on shared hosting. Instead of opening a new connection per request, create the pool once and share it across the app; this shortens response times and keeps you from hitting the connection limit.

Reading Logs

Your app's console.log and console.error output is written to a log file in the application root. If you set a log file path when creating the app, output goes there. To watch it live, use tail -f in the terminal. For an app that crashes on startup, the fastest way to diagnose it is to enter the virtual environment and run the startup file by hand with node app.js; the error message prints straight to the screen. Once you've seen the error, don't forget to stop the process with Ctrl+C.

5. Start and Restart the App

Restart the app every time the code or an environment variable changes. There are two ways:

  • The Restart button on the Setup Node.js App screen.
  • Touching the restart file in the application root from the terminal:
cd ~/nodeapp
mkdir -p tmp && touch tmp/restart.txt

When you set up automatic deployment with Git, you can add the second method to the end of your deploy script. For automatic deployment, see the automatic deployment with cPanel Git Version Control guide.

Practical Performance Tips

  • Use production mode. Frameworks like Express turn on optimizations such as template caching and hide error details when NODE_ENV=production.
  • Minify static files. Build your front end locally as minified output; building on the server is slow and resource-hungry.
  • Keep startup light. The app may be put to sleep after a period without requests and restarted on the first new request. Avoiding heavy work at startup speeds up that first response.
  • Trim dependencies. Removing unused packages from package.json cuts install time and disk usage.

Common Errors

  • 503 or "Web application could not be started": the startup file name is wrong, a dependency is missing, or the code throws an error on startup. Check the log file in the application root and the output of node app.js run in the terminal inside the virtual environment.
  • "Cannot find module": npm install wasn't run, or a manually uploaded node_modules folder is blocking the symbolic link.
  • Static files return 404: if the app is served under a subpath (e.g. /api), check that your routes account for that prefix.
  • Out-of-memory error during build: Next.js or large front-end builds can exceed plan resource limits. Build locally and upload the output.

Shared Hosting or a Coolify Server?

Setup Node.js App is designed for web apps that respond when a request comes in. Some workloads, however, need a server with root access. The table below makes the decision easier:

NeedcPanel Node.jsCoolify server
Express/Fastify API, small web appGood fitGood fit
Background jobs running for hours, queue workersNot a fit; processes can be terminatedGood fit
Always-on WebSocket connections, botsLimitedGood fit
Docker images, Redis, custom system packagesNot possibleGood fit
Large Next.js buildsMay hit resource limitsGood fit
Running a PHP site, email and Node.js from one panelGood fitRequires separate setup

If your project falls into the second half of the table, AI Hosting servers with the Coolify panel are the better choice: the Coolify panel comes preinstalled and offers deployment from GitHub and Docker, automatic SSL certificates, one-click databases and root access. We explain Coolify in detail in the what is Coolify guide.

Next Step

If you want to manage your Node.js API in the same cPanel account as your PHP site, email and database, check out our Laravel hosting plans with the Node.js application manager; Terminal/SSH, Git and NVMe storage are standard. If you're planning always-on services, Docker or AI integrations, you can start with Coolify servers in Istanbul. If you're not sure which infrastructure fits your project, you can open a support ticket with the Sunucu Atlas team.

Frequently asked questions

Which port should a Node.js app use in cPanel?

Don't hardcode the port; use process.env.PORT. The web server routes requests to your app on its own, so you don't need to expose a port like 3000.

Why is the Run NPM Install button grayed out?

No package.json file was found in the application root. Upload the file to the correct folder and refresh the page, and the button becomes active.

Do I need pm2 in cPanel?

No. Setup Node.js App manages the process itself and starts the app when needed. On shared hosting, running a separate persistent process with pm2 can hit resource limits.

Why doesn't my app update after I change the code?

Node.js code runs loaded in memory. After a change, click Restart on the Setup Node.js App screen or touch the tmp/restart.txt file in the application root.

Can I run a Next.js app in cPanel?

You can build it locally and run it with a custom server file, but resource limits can be a problem for large projects. A Docker-capable Coolify server is usually a smoother option for Next.js.

For this guide

Recommended plans

Our Laravel hosting plans include the Node.js application manager, Terminal/SSH and Git in cPanel, so you can publish your API in the same panel as your site and move to AI Hosting with Coolify for always-on services.

SA-DEV-1

cPanel
Recommended

40 GB NVMe disk

$0.69/mo

+VAT

  • Processor2 cores
  • Memory2 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

SA-DEV-2

cPanel

60 GB NVMe disk

$0.98/mo

+VAT

  • Processor3 cores
  • Memory3 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

SA-DEV-3

cPanel

80 GB NVMe disk

$1.37/mo

+VAT

  • Processor4 cores
  • Memory4 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

Laravel Hosting — tüm paketler AI Hosting — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.