How to Set up Node.js Application in cPanel

In this tutorial, you will learn how to easily set up Node.js applications from the cPanel graphical interface or by entering commands in the hosting terminal.

You’ll be able to host your applications with VernalWeb’s infrastructure that supports and installs Node out of the box! Try our Node.js Hosting plans today for top speed and reliability.

How to Set up Node.js Application in cPanel

Create the application

1) Log in to cPanel.
2) In the SOFTWARE section of cPanel, click on the Setup Node.js App icon

Node.js App3) On the Node.js selector page, click on the Create Application button to start the application setup.

Create ApplicationFill in the required fields on the application setup form.

NodeJS Install Variables

  • Node.js version – select your preferred Node.js version from the drop-down list
  • Application mode – choose Development or Production from the drop-down list. You can choose Development initially and change it to Production later on.
  • Application root – the file system location for the application files. The entry will be appended to /home/username to form the complete path to the application files in the cPanel home directory.
  • Application URL – the public URL to your application.
  • Application startup file – the initial file that will be processed when launching the application.

4) When the form is complete, click the Create button.

Package.json

5) After the application is created, an information box is displayed advising that the package.json is required to continue.

The application will launch and display a test page. If you want to see if the test page works, Click the Open button.

6) Click the Cancel button to continue.

Now that a working application is installed, the environment can be enhanced with the package.json settings file and the npm package manager. To install package.json and npm, follow the steps in the next two sections.

Create the package JSON

1) Go back to cPanel’s dashboard. In the FILES section of cPanel, click the File Manager icon to open the File Manager.

2) In the left-hand column of File Manager, click the text of the application root folder.

Application Root

3) Click the +File button to create a new file.

In the New File dialog box, enter the file name package.json and then click the Create New File button.

Create New File4) Once the file is created, Right-click or secondary click on the package.json file in the right-hand column of File Manager and then click Edit. An edit dialog box is displayed.

5) In the Edit dialog box, click the OK button and enter the following text in the editor screen

 

Edit Json File

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

6) Click the Save Changes button to save the file.

7) Click the Close button to close the editor.

Install NPM

1) In the SOFTWARE section of cPanel, click on the Setup Node.js App icon

Setup Node.js App

2) In the Actions column of the Web Applications list, click the pencil icon to edit the application.

Edit Application

3) Click the Run NPM Install button.

The NPM installation runs and presents a success indicator when completed:

Node.js
NPM Install completed successfully

To install packages with NPM and do other command-line tasks related to the application, log in via SSH and enter the virtual environment for the application using the command shown in the information box at the top of the application setup page.

Run Command

How to Set up Node.js Application using Command Line

If you are familiar with using SSH, you may find the command line interface faster and easier than using the cPanel install interface.

To set up a node.js application from the command line, follow these steps:

1) Connect to your account via SSH.
2) Create the Node.js application with the following command:

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

3) Once you are inside your account’s home directory, change to the application directory

cd ~/app

Open your preferred text editor and create the package.json file. In our example, we’ll use the vi editor.

vi package.json

press i to change to insert mode and paste the following text into the editor.

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

Press Escape key followed by : to enter command mode.
Press x followed by Enter key to save and exit the vi editor.

4) Install npm by entering the following command.

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

To install packages with NPM and do other command-line tasks related to the application, log in via SSH and enter the virtual environment for the application using the command

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

Great! Now you know how to install Node.js app using the cPanel or command-line interface.

  • Was this article Helpful ?
  • yes   no