The Node.js selector allows you to easily set up Node.js applications with the cPanel graphical interface or using the command line. Use whichever method you prefer.
To set up a Node.js application using cPanel, use the following procedures.
First, you must create an application. To do this, follow these steps:
On the Node.js selector page, click
Fill in the fields on the application setup form:
When the form is complete, click
The application starts automatically. To view a test page for the application, click
You should see the It Works! message appear.
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 two procedures.
To create the package.json file, follow these steps:
In the left hand column of File Manager, click the text of the application root folder:
Click
In the New File dialog box, type the filename package.json, and then click :
Right-click or secondary click on the package.json file in the right-hand column of File Manager and then click
Type the following text in the editor screen:
{ "name": "app", "version": "1.0.0", "description": "My App", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
Click
Click
To install npm, follow these steps:
In the Actions column of the Web Applications list, click the pencil icon to edit the application:
Click
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:
Users familiar with SSH and the bash shell may find the command line process faster and easier than navigating the cPanel interface. To set up a node.js application from the command line, follow these steps:
cloudlinux-selector create --json --interpreter nodejs --version 11 --app-root app --domain example.com --app-uri app
Change to the application directory:
cd ~/app
Open the vi editor and create the package.json file:
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" }
To install npm, type 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 using SSH, and then type the following command to enter the virtual environment for the application:
source /home/example/nodevenv/app/11/bin/activate && cd /home/example/app
To control the running state of the application, do the following:
cloudlinux-selector stop --json --interpreter nodejs --app-root ~/app
To start the application, type the following command:
cloudlinux-selector start --json --interpreter nodejs --app-root ~/app
To restart (stop and start in one step) the application, type the following command:
cloudlinux-selector restart --json --interpreter nodejs --app-root ~/app
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.