Learn cPanel

Controlling your Web Hosting Account has never been that easy thanks to cPanel web Control Panel!

• Last Updated: 01/30/2020
• ( 12 minutes reading )

How to manage Node.js Applications in cPanel

Introduction

Node.js is an open-source Javascript runtime environment used to compile and execute Javascript code on the Web Hosting Server instead of the client's Web Browser. This means that Node.js dynamically prepares the content of a web page before the same is sent to the client's Web Browser. This approach spares the computing resources of the client's computer device by minimizing Javascript executions. 

Node.js, like every other scripting language, has to evolve, so it is constantly being updated with new features or improvements for already existing ones being introduced. These constant updates are causing the Node.js versions to have a short lifespan. To provide extended support for different versions, Node.js has been forked into several branches that are being developed simultaneously. 

When a programmer creates a Node.js application, the same is coded for a specific Node.js version which quickly becomes outdated and even separated into a new branch. Having the option to select a specific Node.js version for an application requires the Web Hosting Environment to provide support for multiple Node.js versions, however, that is quite hard for achieving natively. 

With our cPanel Cloud SSD Shared Hosting packages, you can enjoy the freedom of choosing whatever Node.js branch is compatible with your project.

In the following lines of this tutorial, we will show you how to utilize the "Setup Node.js App" feature of cPanel. So, without any further ado, let us begin!

 

Accessing the Setup Node.js App feature in cPanel

Before you can go any further with this tutorial, you will have to make sure that you have logged in the cPanel service for your Web Hosting Account. 

Once logged in, cPanel will provide you with a list of all the features it has to offer conveniently separated into feature groups. To access the "Setup Node.js App" feature, you can either search for it using the search tool provided at the top of the page or you can look for the "Software" features group since the "Setup Node.js App" feature is contained in it. 

 

setup-nodejs-functionality

 

When you locate the feature, please click on it. Once you do that, cPanel will redirect you to a new page which we will refer to as the default page for the Node.js feature. 

 

Creating a new Node.js application

To create a new Node.js application, you will have to click on the "CREATE APPLICATION" button displayed in the upper right corner of the default page for the Node.js feature.

 

create-application

 

Once you do that, you will be redirected to a new page where you will have to configure the settings for your brand new Node.js application. Let's review these.

  • Node.js version - Please use this drop down menu to to pick the Node.js version your project will be based on. 
  • Application mode - Please use this drop down menu to choose the mode of your application to be either Development or Production. Please note that this setting will activate the "NODE_ENV" environment variable with a value equal to the selected application mode. 
  • Application root - Please use this text field to set the absolute path to the folder in which the files for your application will be stored. Please note that this is not a relative path, and you will need to specify the home folder for your account (/home/<cpanel username>) as a prefix. 
  • Application URL - Please use this drop down menu and text field to define the URL on which your Node.js application should be accessible. 
  • Application startup file - Please use this text field to define the startup file for your application. Typically, this can be either app.js or index.js. 
  • Passenger log file - The mail log file for your Node.js application. 

At the bottom of the list, you will find a separate section called "Environment Variables". Here you can define new or edit already existing environment variables valid only for the concrete application. 

 

configure-and-deploy

 

When you are done with the configuration please click on the "CREATE" button located in the upper right corner of the page. This will create your Node.js application with the specific Node.js version that you have selected for the same.

cPanel will then provide you with a message indicating how you can access the virtual environment for this Node.js application. 

 

What is a Virtual Environment, and why do you need to access it?

Every cPanel Web Hosting Account exists in the form of an encapsulated entity on the Web Hosting server. As such, every cPanel Web Hosting Account has access to global services like SSH, MySQL, email, and so on by using their binaries. Or in other words, the binaries of the server are globally accessible by every user account. Node.js is also a binary called "node".

As such, there can only be one binary with that name. However, as we have mentioned, you might need multiple Node.js versions, which the single "node" binary cannot provide. In fact, the "node" binary can only support one Node.js version—the one that is globally available on the server. 

Knowing this, we have found a way to provide support for multiple Node.js versions using the same "node" binary. This is achieved thanks to the Virtual Environment feature. Virtual Environment is a method of encapsulation, however, not on the user account level but on an application level. This means that cPanel will create a new virtual environment for every Node.js application you create.

Within every Virtual Environment, cPanel will provide you with a separate "node" binary meaning that every Virtual Environment utilizes the chosen by you "node" binary version. Additionally, every virtual environment utilizes different environment variables that you can set. 

Typically to access the binaries of the Web Hosting Server you will have to login via the SSH protocol. Accessing the Virtual Environment is no different - you will still have to be logged via the SSH protocol and additionally, you will have to execute a command in order to access the Virtual Environment for the concrete Node.js application you are managing. The command is different for each Node.js application and you can obtain it via the application screen in the "Setup Node.js App" feature of cPanel. 

 

enter-virtual-env

 

By copy/pasting this command you will enter into the Virtual Environment for the chosen Node.js application. Inside the environment, any node commands you will be executing will be handled by the chosen node binary version.

 

Node.js virtual environment

 

In addition to the simple tasks of checking the node version and running your Node.js application, you can also utilize npm for managing the dependencies of your application in case you have a package.json file included in the application. Also, you can define different environment variables that will be available only for the application that is utilizing this Virtual Environment.

 

Managing your Node.js applications

Now that you know how to create your Node.js applications, let's see what management actions you can take with those. If you go back to the default page for the "Setup Node.js App" feature, you will see a list of the applications that have been created previously. For each one of those, you will be presented with the following information:

  • App URI - Under this column, you will see the URI from which the application can be accessed.
  • App Root Directory - Under this column, you will see The directory in which the application is stored. 
  • Mode - Under this column, you will see the mode in which the application is running. 
  • Status - Under this column, you will see the application's current status. 
  • Actions - Under this column, you will see the various management actions you can take for each of the applications. 
    • Stop the application
    • Restart the application 
    • Edit the application 
    • Delete the application

 

node-app-table-section

 

If you click on the "App URI," cPanel will redirect you to the front end of your application so you can check how it looks in your Web Browser. 

 

Another area for the management of the concrete application is the "Edit the Application" link, which is displayed in the form of a pencil-like icon. 

 

edit-app-button

 

If you click on the same, you will be redirected to a new page where you can perform different edits on the configuration for the chosen application. 

On the newly displayed page, at the top, you will see three buttons.

  • DESTROY - Please use this button if you would like to delete the application and its configuration. 
  • CANCEL - Please use this button will get you back to the default page for the "Setup Node.js App" feature where all of your Node.js applications will be displayed. 
  • SAVE - Please use this button; in case you have performed any modifications to the configuration of the application, you can Save those by clicking on this button.

Right below the buttons, you will see the command that you will need to enter in order to access the Virtual Environment for this particular Node.js application. 

Next are the "STOP APP" and "RESTART" buttons which you can use to respectively stop and restart the application if necessary.

 

management-buttons

 

Further down the page, you will find the standard configurations for the application which you have set when the application was created. Right below the standard configurations, you will find a section called "Detected configuration files" in which you will be provided with the option to run the "npm install" command of course if the package.json file is stored within the applications root folder.

 

additional-configurations

 

And finally, on this page, you will find the "Environment Variables" section where you will be able to add, edit or remove Environment Variables. 

 

Understanding how the "Setup Node.js App" feature works is essential when it comes to managing your Node.js applications. In case you need any further assistance with this feature or you are facing difficulties understanding how the feature works, please do not hesitate to contact our Technical Support Crew for additional assistance and guidance.

...
Nikola Zgurev
Technical Support Captain

Nikola is an accomplished tech-savvy extraordinaire with over six years of experience in the web hosting field. He started as a customer care representative and quickly rose the ranks to become a support supervisor and, eventually - the head of the technical department in HostArmada. His deep understanding of the client's needs, combined with his technical knowledge, makes him the perfect man to create the ideal harmony between client satisfaction and professional problem-solving. You will often find him creating helpful tutorials, articles, and blog posts that help existing customers get around.