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.
Now click on the Create Application button to add a new app.
In this new view, you will be able to select the version branch for your project.
You can also select if you want to deploy the app in a Development or a Production environment.
You are left with populating 3 fields regarding your project:
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.