Introduction
This article discusses how to install a Node.js application on a cPanel account.
Procedure
To install an application:
- You can complete these steps in three ways
- Create the application's directory relative to the user's home directory.
- In the File Manager, click the "+Folder" button and create the "nodejsapp" directory.
- via SSH or Terminal:
mkdir nodejsapp
- Change to the application's directory.
- In the File Manager, click on the new entry in the sidebar file tree to open the directory you've created.
- via SSH or Terminal:
cd nodejsapp
- Create your 'app.js' start file.
- In the File Manager, click "+File" and name it "app.js"
- via SSH or Terminal, depending on your favorite editor, run:
vi app.js
nano app.js
- The following is a default app.js starting point:
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.
- Follow through to the Application Manager documentation to register this application to the system.