September 2019 - Webx Networks

How to Install a Node.js Application on cPanel


This document describes how to install a Node.js web application. Node.js is a JavaScript runtime that allows you to build scalable web applications.

We recommend that only experienced web developers perform these steps. We are not responsible for any data loss.

Install the Application

To install an application, perform the following steps:

1) Create the application’s directory inside your home directory (outside of public_html). For example nodejsapp.

2) Change to the application’s directory nodejsapp and upload app.js file similar to this one:

Register the Application

After you install the application, register it. To do this, use cPanel’s Application Manager interface (cPanel >> Home>> Software >> Application Manager).

Registering Application in cPanel

In this example, businessx.com represents your website and /myapp is the path where you want the application to load.

After registering the application, you can access it over the web at the Application URL.

Restart the Application

When you want your application to restart after you edit it, create the restart.txt touch file in the application’s tmp directory. This file directs the server to restart the application after you modify it. This action applies your changes to the application.

You must touch the restart.txt touch file each time that you want the server to restart the application.
You must manually create the tmp directory. For example:

$appDir/tmp/restart.txt

node and npm command line

By default node and npm commands are not in your path. To access these utilities, you’ll need to update .bashrc (dot bashrc) file in your home directory and add the following line to it:

export PATH=/opt/cpanel/ea-nodejs10/bin/:$PATH

This will make the utilities available in your execution path. After saving the .bashrc file, log out of ssh/terminal session and then log back in so that the PATH environment variable is loaded. And now you can run commands like the following to confirm they work:

node --version

npm --version

You can go into your app folder and install the modules using npm install package-name.

Back to Top

© 2019 Webx Networks.