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
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
- In cPanel, open the Setup Node.js App tool under Software.
- Click the Create Application button.
- Node.js version: choose the LTS version your project supports. If
package.jsonhas anenginesfield, follow it. - Application mode: choose Production for a live site. This means
NODE_ENV=production. - Application root: the folder where the files will live, for example
nodeapp. Keep this folder outsidepublic_html. - 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. - Application startup file: the name of your entry file, for example
app.jsorserver.js. - 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 -vThe 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:
| Name | Example value |
|---|---|
DB_HOST | localhost |
DB_NAME | kullaniciadi_nodeapp |
DB_USER | kullaniciadi_dbuser |
DB_PASS | A strong password |
JWT_SECRET | A 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.txtWhen 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.jsoncuts 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.jsrun in the terminal inside the virtual environment. - "Cannot find module":
npm installwasn't run, or a manually uploadednode_modulesfolder 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:
| Need | cPanel Node.js | Coolify server |
|---|---|---|
| Express/Fastify API, small web app | Good fit | Good fit |
| Background jobs running for hours, queue workers | Not a fit; processes can be terminated | Good fit |
| Always-on WebSocket connections, bots | Limited | Good fit |
| Docker images, Redis, custom system packages | Not possible | Good fit |
| Large Next.js builds | May hit resource limits | Good fit |
| Running a PHP site, email and Node.js from one panel | Good fit | Requires 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.