Articles on: Dedicated Servers

How to install Node.JS on a Dedicated Server

Node.JS is a great language for developers to easily write many different types of applications, such as Discord bots, web panels, API endpoints, and so much more. With this guide you'll be able to install any version of Node.JS you need.


Installing Node Version Manager


  1. Log into your dedicated server via SSH
  2. Run the command curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash to install the latest version of NVM
  3. It should give a number of commands as output, as seen here:
  4. Copy and paste those commands back into the terminal and run them
  5. Run nvm ls-remote to verify it's correctly installed. If this does not work, try logging out of the SSH and logging back in again


Installing a version of Node.JS


Firstly, you would need to know which version of Node.JS you wish to use. If you're not sure, just go to the Node.JS website and check what the latest "LTS" release is


  1. Log into your dedicated server via SSH
  2. Run the command nvm install AB.CD.XY, replacing AB.CD.XY with the version you wish to use
  3. Run the command node --version to verify it's correctly installed


Running an application


  1. Upload the Node.JS application to your dedicated server, either using something like WinSCP or by using git clone <github link> directly onto the machine
  2. Run cd /folder/where/the/application/is to go to the right folder
  3. Run npm install to install all of the application's dependencies
  4. Run node . to start the application


Making an application automatically start on boot


  1. Install Process Manager 2 globally by running npm install -g pm2
  2. Allow PM2 to start on boot with pm2 startup
  3. Start your application using PM2 by running pm2 start ./index.js --name MyApplication rather than node ./index.js
  4. Run pm2 save so that PM2 will save a list of running apps to disk, so they can be re-opened on next boot
  5. Test this by restarting the machine

Updated on: 26/01/2021

Was this article helpful?

Share your feedback

Cancel

Thank you!