How to Setup, Install and Deploy your Node Js Application with Babal Host?

December 20, 2021 9:04 pm

You can get Node js package in Babal Host, in the following packages.
  • Node js Starter Package
  • Node js Pro Package
  • Professional Plan
Node js is an open source server environment that runs on various platforms i.e. Windows, Linux, Mac OSx, UNIX. It uses javascript on the server. Here are the following procedures to follow for setting up the Node js application in the cPanel interface.
  1. Login to your cPanel. If you do not know how to log in to your cPanel, follow this article.
  2. Scroll down, and in the Software section, select the "Setup Node js App". Setup Node js App
  3. Click on Create Application. cerating application
  4. Fill in the form below, as filled in the photo, and click on the create button. setting up the files - Node.js version: Select your preferred version from the drop-down list. - Application Mode: Choose development or production from the list. For testing, you can initially use development, later on during launch you can change it to Production. - Application root: It is the file system location for application files. The entry should be /home/username to form the complete path in the cPanel home directory. - Application URL: It is the public URL to the application. -Application Startup file: The initial file will first be loaded while launching the application.
  5. The following screen will appear after clicking on create button. app created
  6. Open your site by using the URL: <domainname>.com/app it works node jsIt works.  This is how the working application is installed. We need to enhance the environment with the package.json settings file and the npm package manager. Follow the article below for creating package.json file and installing npm.
#Creating package.json file For creating the package.json file, follow the following steps below.
  1. Go to File Manager in cPanel. opening file manager
  2. Open the app folder inside the domain folder where you setup the node.js app. opening app folder
  3. Click on the +File icon to create the new file. adding file
  4. Name the filename as package.json and click on Create New File button.file naming
  5. Right-click on the package.json file and click on the edit button. clicking on edit
  6. Add the following code in the file and click on Save Changes and then click on close button. adding the codes 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"
    }
    
    
The code for the package.json is completed. Lets go through the npm install command.

#npm install 

Follow the below steps to install npm to the node.js app
  1. Open your cPanel, scroll down and in Software section, Click on "Setup Node App" option. Setup Node js App
  2. Click on the pencil icon, editing the application. editing the application
  3.  Scroll down a bit, click on run NPM Install button. This might take some time to detect the file by this application. It might take 10-20 minutes to install. run npm install
  4. The npm install runs and displays the success indicator of completing the task.

#for installing packages with npm and performing the command-related tasks

See the following steps for setup the node js app and doing the command-related tasks.
  1. Connect to your account to login through SSH.
  2. Create the node js application with the command below.
    cloudlinux-selector create --json --interpreter nodejs --version 11 --app-root app --domain example.com --app-uri app
  3. During inside the home directory, change the directory into the application directory.
    cd ~/app
  4. Open the vi editor and create the package.json file
    vi package.json
  5. Enter i to change to the insert mode and paste the following code in the text 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"
    }
  6. Enter escape followed by : to enter command mode.
  7. Enter x followed by Enter to save and exit the editor.
  8. Now, install npm using the following command.|
    cloudlinux-selector install-modules --json --interpreter nodejs --user example --app-root app
  9. For installing packages with npm and performing other command-line tasks, log in with ssh and type the following command to enter the virtual environment of the application.
    source /home/example/nodevenv/app/11/bin/activate && cd /home/example/app