Tutorials • Apps
Launching a NodeJS application on VPS servers with cPanel
Learn how to launch a NodeJS application on a VPS server with cPanel, including the necessary steps for setting up and efficiently managing the application.
Views 1038Updated 1 anPublished on 25/06/2021by Florin Petran
Introduction
- NodeJS is a runtime environment that allows the use of the Javascript language on the server side (backend).
Requirements
- To leave a NodeJS application we will need the cPanel access data.
Steps
- As an example, we will use a simple javascript code file that we will upload to the hosting.
- We access the cPanel account and log in with the username and password found in the email with the administration details.

- Next, we access File manager from the Files section.

- Here we will create the file named app.js which we will edit and add the code below.
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('Test file \n');
});
server.listen(port, hostname, () => {
console.log(`Server running at https://${hostname}:${port}/`);
});



- The next step is to configure in Application Manager
- We will click on Application Manager in the Software section

- In the page that will open, we will click on Register Application to start the application configuration.

- Here we will be able to modify the following fields:
-Application Name - The name of the application
-Deployment Domain - The address/URL on which the application will run. The address can be customized or the domain used directly
-Application Path - The path to the application's entry file
-Deployment Environment - How we want to launch the application, development or production
-Environment Variables - If you want to add variables, click on Add Variable to specify a name and a value. - cPanel currently only offers NodeJS version 10. If you would like a different version configured, please contact the technical department.
- After defining all the fields, we will click the Deploy button to launch the application.

- Immediately after launch, the NodeJS application will be accessible at the address defined during the configuration.
- In the Application Manager interface, the newly launched application will appear (as well as others that we will add over time). In this list, we will have the option to edit settings, delete, start, or stop applications.
