cPanel, How to Host a NodeJS Application
If you have a custom NodeJS application for your website, here's how to get it working on web.illinois.edu.
Putting your application on the server
Before you can configure your NodeJS application, you need to get the files to the server. After logging into your cPanel dashboard at https://web.illinois.edu, you can transfer the files by:
Once your files are in place on the server, you can configure it to launch. From your cPanel dashboard:
- Under the Software section, select Setup Node.js App.
- Under Create Application, choose Development or Production.
(Development has less caching and more logging. Production has more caching and less logging.)
- Enter the Application root (the directory where you put the application).
- Enter the Application startup file.
- You can add environment variables using the Add Variable button.
- Once you've saved your application, resolve its package dependencies. You can do this automatically or manually.
- The NPM package manager does this automatically based on the package.json file packaged with the application, so all that you’ll need to do is click on the NPM Install button.
- If you are familiar with the command line, you can follow the instructions at the top of the page to gain access to the npm and node commands to make additional changes manually, allowing for a great deal of customization.
Once you have the application configured and the modules installed you can launch it by clicking the Run JS Script on the same page where you configured the application. This executes the application startup file that you defined during setup.
As Node.js applications have several different options, this can bring up another menu with different options to select depending on the application that you’re running. In general, you’ll want to select the “Start” option next.
Finally, you can select the “Open” option to visit your page, and see your application!
Your application generates friendly error pages that can help debug problems, however these are not displayed by default. To turn on friendly error pages, add the following line to your application's .htaccess file:
Hint: If your application runs at yourdomain.web.illinois.edu/myfolder/myapplication, then the correct .httaccess file is:
Once your application is ready for production, you should turn friendly error pages back off by removing the line from your .htaccess file.