Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. Node.js lets developers use JavaScript to write command-line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser.

NPM is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js.

You can also view our guide on Installing NodeJS & NPM on CentOS 7

You can also view our guide on Installing NodeJS & NPM on Ubuntu 16.04/18.04

In this guide, we will explain how to install NodeJS & NPM on a Debian 9 Server.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can quickly deploy your cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Updating System Packages
It is recommended that you update the system to the latest packages before beginning any major installations. Issue the command below:

sudo apt-get update && sudo apt-get upgrade

Step 1: Add Node.js current repository:
At the time of this guide, the latest version of the NodeJS current repository is 11.14.0. Issue the command below to add the Apt repository for that version:

curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -

Add NodeJS LTS repository
For production purposes, the LTS release is recommended. At the time of this guide, this is Node.js 10.15.3 LTS. Issue the command below to add the Apt repository for that version:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

Step 2: Install Node.js
Next, proceed to install nodejs with the command below:
sudo apt-get -y install nodejs

You can also proceed to install development tools to build native add-ons with the command below:

sudo apt-get install gcc g++ make

After successfully installing, you can confirm versions of nodejs with the command below:

node --version
npm --version

Step 3: Install Yarn package manager
This is optional but to install the Yarn package manager, issue the command below:

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

Verify installation with the command below:

yarn --version

To learn more about NodeJS, you can read the official documentation for more information.