Install nodejs on ubuntu

Installing nodejs

sudo apt install nodejs
sudo apt-get install npm

Installing pm2

sudo npm install pm2@latest -g
cd /usr/bin
sudo ln -s nodejs node

Create user to run nodejs

sudo useradd nodeuser
sudo passwd nodeuser
sudo addgroup nodejs
sudo adduser nodeuser nodejs

Using pm2 to start nodejs app

pm2 start hello.js

Using pm2 to autostart nodejs apps

sudo env PATH=$PATH:/usr/local/bin pm2 startup -u nodeuser
sudo su -c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"
pm2 save