1. Home
  2. cPanel
  3. How to Deploy a Node.js Website on cPanel: A Complete Step-by-Step Guide

How to Deploy a Node.js Website on cPanel: A Complete Step-by-Step Guide

Deploying a Node.js website does not have to be complicated.

If you are familiar with traditional PHP hosting, you may initially find Node.js deployment a little different. Instead of simply uploading files to public_html and opening your domain, a Node.js application needs to be configured with the correct Node.js version, application root, startup file, environment variables, and dependencies.

Fortunately, many cPanel hosting environments provide tools such as Setup Node.js App, Application Manager, or Node.js Selector that make the process much easier.

In this guide, we will walk through the complete process of deploying a Node.js website on cPanel—from preparing your application to connecting your domain and troubleshooting common errors.


What You Need Before You Start

Before deploying your application, make sure you have:

  • A cPanel hosting account
  • A domain or subdomain
  • Node.js support enabled on your hosting server
  • Access to cPanel
  • Your Node.js application files
  • A package.json file
  • The application’s startup/entry file
  • SSH or cPanel Terminal access, if available

Your project may look something like this:

my-node-app/
├── package.json
├── package-lock.json
├── server.js
├── public/
│   ├── index.html
│   ├── css/
│   └── js/
└── ...

The important files will depend on your project.

For example, your application might use:

server.js

as its entry point.

Another application might use:

app.js

or:

index.js

Do not assume the startup file is always server.js. Check your application’s configuration before creating the cPanel application.


Step 1: Prepare Your Node.js Application

Before uploading anything to cPanel, make sure the application works correctly on your local machine.

For example:

npm install

Then start the application:

npm start

or, depending on your project:

node server.js

If the application does not work locally, deploying it to cPanel will usually not fix the problem.

Check package.json

A typical Node.js project may have a package.json similar to:

{
  "name": "my-node-app",
  "version": "1.0.0",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^5.0.0"
  }
}

The exact contents will depend on your application.

One particularly important section is:

"scripts": {
  "start": "node server.js"
}

This tells Node.js how to start the application when npm start is used.


Step 2: Choose an Application Directory

Your Node.js application should have its own directory.

For example:

/home/username/my-node-app

or:

/home/username/apps/my-node-app

The exact location is up to you, but keeping the application separate from unrelated website files makes the deployment easier to manage.

Important: Application Root vs Document Root

This is one of the most common sources of confusion.

The application root is where your Node.js application files live.

The document root is the directory traditionally used to serve files directly for a domain.

For a Node.js application, you normally configure cPanel to send requests for your domain or subdomain to the Node.js application rather than treating the application like a normal PHP website.

For example:

Application Root:
/home/username/my-node-app

and:

Application URL:
https://example.com

The exact configuration depends on your cPanel environment.


Step 3: Upload Your Node.js Application

There are several ways to upload your project.

Option 1: cPanel File Manager

Open:

cPanel → File Manager

Navigate to your home directory and create a directory for your application.

For example:

my-node-app

Upload your project files into that directory.

Your directory should eventually contain files such as:

my-node-app/
├── package.json
├── package-lock.json
├── server.js
└── ...

Option 2: Git

If your project is stored in Git, you can use cPanel’s Git features or clone the repository through SSH, depending on what your hosting provider supports.

For example:

git clone https://github.com/example/my-node-app.git

Option 3: SSH/SFTP

You can also upload the project using SFTP or another supported deployment method.

For larger applications, Git or SFTP can be more convenient than uploading many individual files through File Manager.


Step 4: Open the Node.js Application Manager

Now log in to cPanel.

Look for an option such as:

  • Setup Node.js App
  • Node.js Selector
  • Application Manager

The exact name depends on the hosting provider and server configuration.

Open the Node.js application management interface.

You should see an option similar to:

Create Application

or:

Create Node.js Application


Step 5: Select the Node.js Version

Choose the Node.js version required by your application.

For example:

Node.js Version: 20.x

or another version supported by your project and hosting server.

Why does the version matter?

Node.js applications can depend on specific Node.js versions.

For example, an application developed with a modern Node.js release may not work correctly on an older version.

Check your project’s requirements before selecting the version.

If your package.json contains an engines section such as:

"engines": {
  "node": ">=20"
}

make sure the cPanel application uses a compatible version.


Step 6: Select the Application Mode

You may see options such as:

Development
Production

For a live website, select:

Production

Development mode is generally intended for testing and development.

Production mode is the appropriate choice for a public website unless your hosting environment or application requires something different.


Step 7: Configure the Application Root

Enter the directory where you uploaded your application.

For example:

my-node-app

cPanel may automatically translate this into something similar to:

/home/username/my-node-app

Make sure the application root actually contains your Node.js application.

You should be able to find:

package.json

inside the selected directory.


Step 8: Configure the Application URL

Next, select the domain or subdomain where you want the application to be accessible.

For example:

example.com

or:

app.example.com

If your application is intended to run at:

https://example.com

configure the application URL accordingly.

If you are deploying it under a subdomain:

https://app.example.com

select that subdomain.


Step 9: Set the Startup File

The startup file is the file Node.js uses to start your application.

Common examples include:

server.js
app.js
index.js

For example:

Startup File: server.js

If your project starts from app.js, then use:

app.js

The filename must match the actual file in your application directory.

A common mistake

Do not enter:

/home/username/my-node-app/server.js

if the cPanel field expects only the startup filename.

In that situation, use:

server.js

Always follow the format required by your particular cPanel interface.


Step 10: Configure Environment Variables

Many Node.js applications require environment variables.

These may contain settings such as:

NODE_ENV=production
PORT=3000
DATABASE_URL=...
API_KEY=...

In cPanel, these are usually configured through the application’s environment-variable section.

For example:

NODE_ENV    production

You might also have:

DATABASE_HOST
DATABASE_USER
DATABASE_PASSWORD
DATABASE_NAME

depending on your application.

Keep credentials out of your source code

Avoid hard-coding passwords and API keys directly into files such as:

const password = "mypassword";

Instead, use environment variables:

const password = process.env.DATABASE_PASSWORD;

This makes the application safer and easier to configure between development and production environments.


Step 11: Make Sure Your Application Uses the Correct Port

This is especially important when deploying Express or similar Node.js applications.

A common local setup looks like:

app.listen(3000, () => {
    console.log("Server started");
});

On managed cPanel environments, you generally should not hard-code the production port.

Instead, use the port provided by the hosting environment:

const port = process.env.PORT || 3000;

app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});

This allows the application to use the port assigned by the hosting environment while still allowing local development on port 3000.


Step 12: Install Node.js Dependencies

Once the application has been created, dependencies need to be installed.

Open:

cPanel → Terminal

or connect through SSH if your hosting provider allows it.

Navigate to the application directory:

cd ~/my-node-app

Then install the dependencies:

npm install

This reads your:

package.json

and installs the required packages.

If your project already contains a package-lock.json and you want a clean, reproducible production installation, you may use:

npm ci

when appropriate for your deployment workflow.

After installation, you should see:

node_modules/

inside the application directory.


Step 13: Start or Restart the Application

Return to the Node.js application interface in cPanel.

After configuring the application, use the available:

Start Application

or:

Restart Application

option.

If you have just created the application, start it.

If you changed application files or environment variables, restart it so the changes take effect.


Step 14: Test Your Website

Open your domain in a browser:

https://example.com

If everything is configured correctly, your Node.js application should load.

Test the important parts of the website:

  • Homepage
  • Login
  • Registration
  • API endpoints
  • Database connection
  • Forms
  • Static assets
  • File uploads
  • Authentication
  • Any external APIs

Do not only check whether the homepage loads.

A website can display its homepage while its database connection or API endpoints are still broken.


Step 15: Enable HTTPS

For a production website, HTTPS is essential.

Your website should ideally be accessible through:

https://example.com

rather than:

http://example.com

On many cPanel servers, SSL certificates can be managed through:

cPanel → SSL/TLS Status

or through the hosting provider’s SSL/AutoSSL system.

After SSL is configured, test the website using HTTPS.

Also check that your application does not contain hard-coded HTTP URLs where HTTPS is required.


Final Thoughts

Deploying a Node.js website on cPanel is mainly about connecting several pieces correctly: your application files, Node.js version, startup file, dependencies, environment variables, domain, and the cPanel application manager.

Once you understand what each setting does, the process becomes much easier.

The most important thing to remember is that a Node.js application is not deployed exactly like a traditional PHP website. You are running an application process behind the hosting environment, and cPanel provides the interface needed to manage that application.

If something goes wrong, don’t immediately start changing multiple settings. Check the Node.js version, startup file, application root, dependencies, environment variables, and logs one by one.

With those configured correctly, deploying a Node.js application on cPanel can be a straightforward and repeatable process.

Was this article helpful?

Related Articles

Scroll to Top