Overview
This guide explains how to deploy a Node.js application on cPanel using Application Manager. It includes a basic Node.js app and an Express.js version for future use.
Server Details
Home Directory: /home/yourusername
Node Version: 16.20.2
Node Path: /bin/node
Python Version: 3.9.25
Python Path: /bin/python3
Example Folder Structure
/home/yourusername/
│ └── demoapp/
│ ├── app.js
│ ├── package.json
│ └── tmp/restart.txt
── public_html/
Basic Node.js App
app.js:
const http = require(“http”);
const PORT = process.env.PORT || 3000;
http.createServer((req, res) => {
res.writeHead(200, {“Content-Type”: “text/html”});
res.end(“Node.js app running on cPanel”);
}).listen(PORT);
package.json:
{
“name”: “demoapp”,
“version”: “1.0.0”,
“main”: “app.js”
}
Express.js Version
Install Express:
npm install express
app.js:
const express = require(“express”);
const app = express();
const PORT = process.env.PORT || 3000;
app.get(“/”, (req, res) => {
res.send(“Express app running on cPanel”);
});
app.listen(PORT, () => {
console.log(“Server running…”);
});
cPanel Application Manager Settings
Application Name: demoapp
Deployment Domain: yourdomain.com
Base URL: /nodeapp
Application Path: demoapp
Environment: Production
Testing via SSH
cd /home/yourusername/ demoapp
/bin/node app.js
curl http://127.0.0.1:3000
Restart Application
touch /home/yourusername/demoapp/tmp/restart.txt
Access URL
https://yourdomain.com/nodeapp