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/ && update-rc.d defaults"
pm2 save

Leave a Reply

Your email address will not be published. Required fields are marked *