Skip to content
cPanel Guides

How to Host a Node.js App in cPanel

Run a Node.js app on cPanel hosting without a VPS: create the app in Setup Node.js App, upload your code, install packages, set environment variables and start it.

Hosting a Node.js app in cPanel with Setup Node.js App, in four steps

You can host a Node.js app on cPanel hosting without a VPS. In cPanel, open Setup Node.js App, create an application, choose the Node.js version, the folder for your code and the start file, then install your packages and start the app. At HostGrap, Node.js apps are supported on cPanel Plus and bigger plans in Europe and Singapore, on SL Plus and bigger plans on our Sri Lanka servers, and on every Business cPanel plan. This guide walks through each step.

Which HostGrap plans support Node.js?

Node.js apps are included on the plans in the table below. The smallest plans in each range, such as Core, SG Lite and SL Lite, run PHP websites such as WordPress, but not Node.js apps.

Plan rangeNode.js apps
cPanel hosting, EuropePlus, Prime and Max
cPanel hosting, SingaporeSG Plus, SG Pro and SG Max
cPanel hosting, Sri LankaSL Plus, SL Pro and SL Max
Business cPanel hostingEvery plan

If you are on a smaller plan, you can upgrade in your client area without losing your website or email.

Is cPanel the right place for my Node.js app?

cPanel suits websites and APIs built with frameworks such as Express, Next.js in server mode or Nuxt, small bots and dashboards. Your app runs behind the web server on your own domain or subdomain, with free SSL.

Shared hosting has limits, like any plan: your app shares the CPU and RAM of your account, and it can't keep long-running background jobs or listen on its own network ports. If your app needs root access, its own process manager, WebSockets at scale or software of your own, a VPS is the better fit. Read shared hosting vs VPS if you are not sure.

How do I create a Node.js app in cPanel?

  1. Log in to cPanel and open Setup Node.js App in the Software section.
  2. Click Create Application.
  3. Choose the Node.js version your app needs. Use the same major version you use on your own computer.
  4. Set the Application mode to Production.
  5. In Application root, type the folder for your code, for example myapp. cPanel creates it in your home folder. Keep it outside public_html, so your source code isn't public.
  6. In Application URL, choose the domain or subdomain where the app will open, for example api.yourdomain.lk.
  7. In Application startup file, type the file that starts your app, for example app.js or server.js.
  8. Click Create. cPanel creates the app and shows a command for entering its environment in the terminal.

How do I upload my code and install packages?

Upload your code to the application root folder with File Manager, FTP or Git. Don't upload the node_modules folder: it is large and is created on the server instead.

Back in Setup Node.js App, open your app and click Run NPM Install. cPanel reads your package.json and installs the packages. You can also run npm install yourself in Terminal, after running the command cPanel showed you to enter the app's environment.

How do I set environment variables?

In your app's settings in Setup Node.js App, add each variable under Environment variables, such as NODE_ENV, DATABASE_URL or an API key, and click Save. Keep secrets here instead of in your code. Restart the app after changing them.

How do I start, restart and check my app?

Click Start App, or Restart after you change your code or settings, and open the Application URL in your browser. Your startup file must start a web server. Use the port the platform gives your app in process.env.PORT, for example:

const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello from HostGrap'));
app.listen(process.env.PORT || 3000);

If the page shows an error, check that the startup file name and the Node.js version are right, that npm install finished without errors, and that your app starts on your own computer with the same settings.

Can my Node.js app use a database?

Yes. Every plan that runs Node.js also includes MySQL databases, and the Europe, Singapore and Business plans include PostgreSQL too. Create the database in cPanel and connect to it from your app on localhost. See how to create a PostgreSQL database in cPanel.

Need a hand? HostGrap AI on live chat or WhatsApp can turn on cPanel Terminal (SSH) and check your account's resource limits, and our team can help if your app doesn't start.

Share this article

More from the blog

All posts