Articles on: Control Panel

How to create a node.js application via CPanel?

Node.js is a tool for creating various web applications based on Javascript code. It can be used to create applications to fill a wide variety of features, from streaming to e-commerce.

Creating a node.js application can seem quite complex. This is especially true if you are not comfortable with the programming language. But don’t worry, we have designed this tutorial to accompany you through the process.

In this article, we will first briefly present what a node.jse application is. We will then see two different methods of proceeding to create your web application. By following the detailed instructions in this tutorial, you should be able to successfully complete your project.

Table of Contents



Introduction to web node.js applications
Method 1: Set up a node.js application with the CPanel interface
Create a node.js application
Create a package.json file
Install npm
Method 2: Set up a node.js application via SSH command lines
Conclusion


What is a node.js application?



To fully understand the concept of node.js, we must first focus on programming languages. Javascript code is already used by your web browser to communicate. Like HTML and CSS, it is a script used by web developers for programming.

Node.js appeared when someone had the genius idea to use Javascript beyond the simple browser. Before that, developers had to work with various programming languages and sometimes with a different front-end and back-end framework.

All this may seem complex, but we can summarize it by saying that it is a tool that makes it possible to simplify the work of web development. Thanks to it, your web browser and your web server speak the same language, the JavaScript code.

An open source platform for your web server to communicate in Javascript



Node.js is an open source, multi-platform Javascript execution environment. It allows the creation of various server-side or network applications. As the front end and back end of the application are on the same framework and in Javascript code, the work of the developers is simplified.

Web applications can be programmed in an express way in comparison with applications developed in Java. The performance and scalability of Node.js applications are also superior to other operating systems in development.

Setting up a Node.js application via the CPanel interface



To set up a node.js application through your CPanel control panel, simply follow the instructions below through these few steps.

Step 1: Create a web node.js application



To get started, you must first connect to your CPanel control panel via the Ex2 site customer area.

In the "software" section of your CPanel interface, you should see a tool called Setup Node.js App. Open it to access the program window.



On the page that appears, click on the "Create Application" button in the top right to start the creation of your application.



You must then fill in the fields of the application implementation form.



The information requested is as follows:


Version node.js: you can choose the version you want from the options in the drop-down menu.

Mode of the web application: it is possible to choose in a "Development" mode used for the design, and a "Production" mode once the project is completed.
Application root directory: the file system location for your node.js application files. The full address will be adjusted automatically (by adding "Home/username") to lead to the Home directory of your CPanel.
Application URL: the internet address of your application.
Your application startup file: the name of the file used to launch your application.

Once you have completed all the boxes, you must launch the creation of your application by clicking the Create button.

You will then see the name of your application appear on the node.js editor page. To connect to it, just click on the "Open" icon next to the name. You should then see a message saying "It works!" confirming the success of the operation.

Once this is done, it is time to create a package.json parameter file, before installing npm.

Step 2: Create a package.json file



The npm packages use a package.json file containing project metadata. This file is used to transmit information to npm about the project identity and project dependencies.

To create a package.json file, follow the instructions and complete the following steps. First, open your Cpanel control panel and open your File Manager.



In the column on the left of your screen, select your application folder and open it.



You must then click on the "+ File" button to create a new file.



In the window to create a new file, enter the name package.json in the box provided. Then click on "Create New File" to confirm.



The new file should then be visible in your file manager. Click on it with the right mouse button to bring up a drop-down menu.

Click on the "Edit" option, which will bring up a window.



This time click on "OK" to start editing the file. On your text editor screen, enter the following text:

```
{

"name": "app",
"version": "1.0.0",
"description": "My App",
"main": "app.js",
"scripts": {
"test": "echo "Error: no test specified " && exit 1"
},
"author": "",
"license": "ISC"
}
```
Once done, click the "Save Changes" button to save the file.



You can then click on the "Close" button to close the editor. You just have to install npm to have finished setting up your node.js application.

Step 3: Install the npm package manager



The npm software is a multi-platform operating system that is used by default in any Javascript environment. It accompanies node.js since version 0.6.3, so its installation is absolutely necessary.

Its name, npm stands for Node Package Manager or node package manager. It is a very comprehensive tool that includes an online ordering client (called npm) and an online database of public and private packages (called npm registry).

The register is accessible via the customer, and the whole thing is in Javascript code. npm not only allows you to install server-side APIs, but also simplifies the process of updating them.

To install npm, you must access the node.js application editor on your Cpanel control panel.



In the "Actions" column of your application page, click the pencil icon to edit it.



In the section showing the configuration files detected by the editor, click the "Run NPM Install" button.



The installation should be done automatically, and a message should announce the success of the operation once it is completed.

Adding npm packages to your project’s operating system



You can add features to your application through npm packages. For example, we can think of executable files in source code or configuration files.

To do this, you must connect to your SSH access and access the virtual environment of your application.

To connect to it, you must copy the following command line to the top of the installation window. Again, replace the word "example" with the appropriate term for your case.

/home/exemple/nodevenv/app/10/bin/activate && cd /home/exemple/app

Installing a Node.js application using SSH command lines



To get started, access your CPanel control panel. Then log in to your SSH access, accessible in the security features section.



Open the program and copy the following command line to create a web application. Obviously, the example.com domain name must be replaced by the URL of your site.

cloudlinux-selector create --json --interpreter nodejs --version 11 --app-root app --domain example.com --app-uri app

You must then define the directory associated with your application with this command line:

cd/app

Then open your vi text editor and create a package.json file by typing:

vi package.json

For the next step, you need to change the command line insertion mode. To do this, simply press the "i". Then copy and paste the following code:

```
{

"name": "app",
"version": "1.0.0",
"description": "My App",
"main": "app.js",
"scripts": {
"test": "echo "Error: no test specified " && exit 1"
},
"author": "",
"license": "ISC"
}
```

Then press the "Escape" button (ESC, on your keyboard) followed by ":". This gives you access to the "control mode". You must then press "x" then "enter" to save the changes and exit your text editor.

Now start your npm package manager installation with the line of as follows. Again, of course, you have to replace the word example with the appropriate term.

cloudlinux-selector install-modules --json --interpreter nodejs --user example --app-root app

Once this is done, both your node.js and npm applications are installed and operational. However, you have access to very few features for your project.

To install packages with npm or run other command lines related to your application, you need to connect via your SSH access. To access the virtual environment of your application, you must use the following command line:

source /home/example/nodevenv/app/11/bin/activate && cd /home/example/app

You can then change the activity status of your node.js application and update it whenever you want.

To start your application, use the following command line:

cloudlinux-selector start --json --interpreter nodejs --app-root ~/app

To disable your application, use this line:

cloudlinux-selector stop --json --interpreter nodejs --app-root ~/app

To restart and reset your application, the command line is as follows:

cloudlinux-selector restart --json --interpreter nodejs --app-root ~/app

We hope this article has helped you in your project to create a node.jse application. We also hope to have taught you a little more about this fabulous web development tool based on a Javascript environment.

Updated on: 28/03/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!