Setup Node.js Application in cPanel
We have Cloudlinux installed on shared hosting server which comes with Python and Node JS support. In this tutorial, WE will learn how to easily set up Node.js applications from the cPanel interface.
In order to set up a Node.js application using cPanel interface, use the following steps.
Step #1: Create the application
First, you must create an application. To do this, follow these steps:
Log in to cPanel >> Software >> Setup Node.js App
On the Node.js selector page, click CREATE APPLICATION to start the application setup:
Fill in the fields on the application setup form:
- Node.js version – select your preferred version from the drop down list
- Application mode – choose Development or Production from the list. Development may be chosen initially and changed to production later.
- Application root – the file system location for 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 address of the application on the Internet.
- Application startup file – the initial file that will be processed when launching the application.
Once all information is properly submitted, click CREATE:
The application starts automatically. To view a test page for the application, click OPEN:
You should see the “It Works!” message appears with the installed version.
Now that a working application is installed, you can enhance the environment with the package.json settings file and the npm package manager.
To do this, follow the next steps:
Step #2: Create the package.json file
To create the package.json file, follow these steps:
cPanel >> File Manager
In the left hand column of File Manager, click the text of the application root folder:
Click +File to create a new file:
In the New File dialog box, type the filename package.json, and then click Create New File:
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 appears:
In the Edit dialog box, click OK.
Type the following text in the editor screen:
"description": "My App",
"test": "echo \"Error: no test specified\" && exit 1"
Click Save Changes to save the file and Click Close to close the editor.
Step #3: Install npm
To install npm, follow these steps:
cPanel – Software – Setup Node.js App
In the Actions column of the Web Applications list, click the pencil icon of the application you want to edit >> Click Run NPM Install >> The NPM installation runs and displays a success indicator when complete.
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:
Great! Now you know how to install Node.js app using the cPanel interface.