Self Help Documentation
How to install a Node.js application in cPanel
Introduction
In this article, we will explore the process of setting up a Node.js application on a cPanel account.
Procedure
To install a Node.js application follow the below steps:
- Log in to the server as the cPanel user via SSH or ‘Terminal’ in cPanel.
- Create the application’s directory relative to the user’s home directory using the following command:
mkdir nodejsapp
- Change to the application’s directory.
cd nodejsapp
- Create the app.js file with a text editor. It is strongly recommended that you create the file with this exact name because Passenger searches for this filename when it executes.
- Add the application’s configuration to the app.js file. This will resemble the following example:
const http = require('http')
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World! NodeJS \n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Save app.js file and close the editor.
Please note after installing that application, it must be registered in cPanel with “Application Manager“.