How to use the Node.js Selector

Updated on Oct 15, 2018

As it is our intention to provide an easier way for new coming developers to create and manage their Node.js projects we have now implemented their Node.js selector on all of our Shared Hosting Servers. In this tutorial, we will show you its functionality and how to start from scratch with Node.js.

 

To access the Node.js Selector, you will first need to log in your cPanel account. Then look for Setup Node.js App or search for the same via the search field in the top right corner of the screen.

 

How to access the Nodejs selector via cPanel

 

Now click on the Create Application button to add a new app.

 

How to create a nodejs application via the Selector

 

In this new view, you will be able to select the version branch for your project.


Selecting the nodejs version for your project

 

You can also select if you want to deploy the app in a Development or a Production environment.

 

Selecting the applocation mode for your nodejs app

 

You are left with populating 3 fields regarding your project:

  • Application root - The physical path to the files of your application on the web hosting server. Please bear in mind that the path should not include “/home/user” or in other words, it starts from there.
  • Application URL - Here you should choose whether the application should be accessible on primary, addon or subdomain as well as if the application should be accessible from a subfolder or directly from the actual domain.
  • Application startup file - The actual file which the application will be using when it is started. This corresponds to node filename command which we have previously used.
  • Environmental variables – Usually, variables for projects are global and are added to a .env file in your project’s directory. However, with the Node.js selector, you can set up environmental variables from within the configuration page of each application. That way, you can have the same variable for different applications representing different values.
     

    For example, you can add a PORT variable with the port’s number as value for one of your applications and then use the same PORT variable with a different value for another application. Having connections to different databases each with its own value for the SECRET_KEY variable works on the same principle. This is the true strenght of environmental variables and the reason why they are preferred from an utility view point.


Click the Create button once you are ready. If you have created a new Node.js application, accessing the application URL now will lead you to a default screen showing the version which you chose and the text “It works!”. You can now navigate to the .js file’s location via cPanel’s File Manager and start editing the default code snippet which is:
 

var http = require('http');

var server = http.createServer(function(req, res) {

    res.writeHead(200, {'Content-Type': 'text/plain'});

    var message = 'It works!\n',

        version = 'NodeJS ' + process.versions.node + '\n',

        response = [message, version].join('\n');

    res.end(response);

});

server.listen();



By creating a placeholder in the Node.js Selector for an existing project, you will effectively add that project and will be able to use the Selector’s start/stop/restart functionality.

On this page...

    Node.js Hosting

    • Multiple Node Versions
    • 24/7 Node.js Support
    • Free Domain Transfer
    • Hack-free Protection
    • Fast SSD Storage
    • Free Node.js Transfer
    • Free Cloudflare CDN
    • Immediate Activation
    View More