Via cPanel
To get started with Node.js and creating a new application, begin by logging on to cPanel. Then, click the icon Setup Node.js App
under Software
.
Once there, you can see all your existing Node.js applications, and also create a new one:
After clicking the Create application
button, you get to adjust some settings for your app:
The six available options imply the following:
Node.js version
– the version of Node.js you want to use.Application mode
– here you select if the app should be run in development or production mode.Application root
– the folder on the server where you’re going to upload the files for the Node.js application. Keep in mind that the application root shouldn’t be the same folder as the document root for the domain you use (below).Application URL
– the domain and URI where the app should be accessible. Leave it blank to run the application directly on the domain. To use a specific directory, enter/directory
, e.g./node-app
to make your application accessible viayourdomain.com/node-app
.Application startup file
– unless you have a specific startup file for your app, you can leave this field empty. If the field is left blank, cPanel will create anapp.js
file for you.Passenger log file
– here you set a directory where you wish logs from the application to be saved.
Once you’re done adjusting the settings, click Create
. Now a virtualenv
will be created where you can install Node.js packages for your application. A virtualenv
in the Node.js world can be described as a virtual environment where you can install packages that will not interfere with the system or with other virtualenv
s. Thus, it’s a way to separate your different Node.js environments. You can access a specific virtualenv
after logging on to your web hosting account via SSH. More information about connecting via SSH can be found here.
After initial setup, you can see your new installation in the list of created Node.js applications.
If you click the pen icon, you will get access to the settings for the application:
Here, you will see information about the Node.js app that is set up, and you can also edit the settings.
On top, you have a few buttons to manage your application:
Destroy
– delete your application.Cancel
– discard changes and return to the list of applications.Save
– save changes made to the application.
Under the buttons, you’ll find Enter to the virtual environment
. This command can be copied and run via SSH to activate the virtual Node.js environment (virtualenv
) for your application. Please refer to the section above regarding virtualenv
and SSH access.
A bit further down, you’ll find more buttons:
Stop app
– stop the Node.js application. Will change toStart app
if the application is currently stopped.Restart
– restart the application.
You can also manage settings for your application:
Node.js Version
– the chosen Node.js version.
Application mode
,Application root,
Application URL
,Application startup file
samtPassenger log file
– please refer to the section above regarding these.Detected configurations files
– here you may install various node packages via npm.Environment variables
– here you may set various environment variables for your application.
Via SSH
You may also manage certain aspects of your Node.js application via SSH.
Restart a Node.js application
To restart a Node.js application via SSH, begin by connecting to your web hosting account via SSH.
Go to the directory that you’ve chosen as application root for the app when you created it (according to the instructions above).
Then create the folder tmp
in your application root if it doesn’t already exist. Then create or modify the file restart.txt
in that folder to force your application to restart. For example, you may use the following command after cd
‘ing to the correct folder:
touch tmp/restart.txt
Select Node.js version
If you require Node.js to run certain cli scripts/programs, and want to select what version of Node to run, you can use nvm
(Node Version Manager).
To get started, you need to log on to your web hosting account via SSH.
You’ll find nvm here: https://github.com/creationix/nvm
To install it on your account, connect to the account via SSH and run their install script (please refer to the URL above for instructions). Then run the following command to enable nvm:
. ./.bashrc
If you for example want to install the latest version of Node 10, run:
nvm install 10
Once the installation is completed, you can set version 10 as default by running:
nvm alias default 10
If you need the exact path to the node binary, you can use this command:
nvm which VERSION
(swap out VERSION
for the version you wish to check, for example 10
).