
While a vast majority of applications in use across our network are PHP applications, and the next most popular language is straight HTML, these aren’t the only languages supported on our hosting servers! They’re also capable of hosting cgi-bin applications (often Perl), Ruby (including the on-Rails variant), Python, and Node.js.
This article will focus mostly on Node.js use since it’s starting to become more popular.
What makes Node.js different?
Since PHP is the most popular choice, it has native support built into the webserver so no special tricks are required to get PHP to work. If a request to a specific URL lands on an index.php file, the server just knows how to handle the request, running that PHP code, and waiting for PHP to return the response headers and HTML output to pass along to the user visiting your site.
Unlike PHP, a Node.js application is a single “compiled” program designed to handle not just a specific location on a site, but all requests for a website. It’s not compiled in the normal sense though since Node.js is still a ‘Just in Time’ language that converts to program code as it goes, but we’re getting a bit too deep into the weeds to really discuss how this works here. The important point is that since this is how Node.js works, it tends to run very quickly compared to PHP, as long as it’s set up properly.
Wait, All Requests?
Yes, Node.js is technically its own tiny webserver, and everything for your website gets sent through it, including static content like javascript files, images, and CSS. Your application should probably use the Node.js Express module so that static resources can be served and cached by the webserver. If you don’t use it, app performance will probably suffer under higher loads! See this Cloudlinux Coummunity forum thead for full details on the topic.
Before you Begin
There’s two big warnings that apply to Node.js applications being deployed on our servers! The resource limits applied to all shared hosting accounts means that:
- The Starter Plan hosting package does not meet the requirements for Node.js deployment. For this reason we have disabled the icons in cPanel normally used for this task on this plan. All other packages still have these features enabled.
- There are not enough resources on shared hosting to run “npm run build”. This means you will not be able to use the server as a development platform to make your Node.js application. The “npm run build” command can often require many gigabytes of memory to run properly, so your application will need to be developed and built on your own local equipment (or a VPS), and then transferred to our server after being built.
Getting Started
First, create a new folder outside of public_html to use as your node.js application folder. It’s very important that your Node.js app folder be outside of public_html because you do not want web requests to be able to retrieve your application source code.
Take a full copy of the entire Node.js application directory (exclude the node_modules folder), and upload it to your new project directory on the server. FTP works for this, but the easiest method is to just zip it up and transfer the zip file to the server, then extract it using the cPanel file manager.

Once your application files are in place, head over to the Software section in cPanel and look for the Setup Node.js App icon. On the next page, click the blue Create Application button on the right. You’ll get this form:

Some Notes About this Form:
- Make sure you set the Node.js version to the same one you used when you built your application locally.
- Application mode should be set to Production for a pre-built application.
- The Application root setting is the path to the Node.js app folder relative to your home directory. Do not put /home/username/ at the start of this path.
- The second box in the Application URL field is for the subdirectory. Do not prefix it with a “/”. If this box is left blank, the application will be installed to the root of your domain.
- The Application startup file should be set to the .js file your application uses to launch. It’s usually ‘app.js’ but may be different depending on how you built your project. If this is not provided, it will default to ‘app.js’ and if this file doesn’t exist, it will be created, and filled with a simple ‘It works!’ page.
- The Environment Variables section is for advanced users. Use it only if you know what you’re doing!
- This form will also create the folder for the Application URL if it doesn’t exist, and it will write to the .htaccess file for that folder. Do not modify this file!
- Any content already at the Application URL will be “covered up” by the Node.js app. You can take advantage of this by installing a “maintenance” page at that location that will only show up when your Node.js app is shut down.
Post-Setup Steps
After setting up the application, you should then click the run NPM install button. This will tell the core node.JS framework to install any node dependencies your application requires to the folder. This will rebuild and replace the node_modules folder you excluded earlier. Once this is completed, restart the Node.js server using the controls in cPanel.
You should then be able to visit your site in a browser and see the results of your Node.js application online. If you do not have a “Plus” hosting plan, the first startup of a Node.js app can sometimes take a minute to run and get ready so be patient!
If you are just trying it out and didn’t upload any of your own code, you should see the ‘It works!’ page when you visit the application URL.
