Introduction
This article discusses how to install a Node.js application on a cPanel account.
Procedure
To install an application:
-
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.
mkdir nodejsapp
- Change to the application's directory.
cd nodejsapp
- Create the
app.js
file with a text editor.
Please note we strongly recommend 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 the changes.
- Close the text editor.
Please note after installing that application, it must be registered in cPanel with "Application Manager."