How to install nodejs on ubuntu

Node.js has grown in popularity in recent years because it speeds up site loading, with everything loaded on the client side. This post shows how to install Node.js on Ubuntu.
Node.js is usually used together with Nginx. We’ll cover the Nginx configuration in another post and go straight to installing Node.js here.
There are 3 methods to install Node.js. We’ll use Node Version Manager (NVM). You can also install it from the Linux repositories with simple apt commands, but the version there is quite old.
First, download the latest version of NVM:
sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh | bash
Now load NVM in your current terminal:
sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh | bash
To verify the installation, run nvm --version
To install the version you want, run the command below and replace X with your version:
nvm install XXXX
To run Node.js: nvm use xxx
You can now create a test page with Node.js in the Nginx root, as shown in the picture below.