Setup Production Server Locally For NodeJS Applications

Today, I will be documenting my experience on how I set up a server that can serve my NodeJS applications. This server will auto-start once the machine restarted.

This guide is for Ubuntu Server.

  • Download and Install NodeJS
curl -fsSL https://deb.nodesource.com/setup_x.x | sudo -E bash -
sudo apt-get install -y nodejs
  • Install PM2 globally
npm install pm2 -g
  • Go to your application directory and start your NodeJS app using pm2. In my case my folder is in /var/www/api and the name of my startup file is app.js
cd /var/www/api
pm2 start app.js
  • You can check all running apps under pm2 by executing the command below
pm2 list
  • Now, we will make sure that our app will auto start if ever the server machine is restarted. So, we will execute this command below
pm2 startup
pm2 save
  • And that’s it! Pancit 😀

Leave a Comment

Your email address will not be published.

Free Web Hosting