Skip to content

Instantly share code, notes, and snippets.

@brunoti
Created April 4, 2021 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunoti/ac29d5d70e90ce91b535a291fabb2924 to your computer and use it in GitHub Desktop.
Save brunoti/ac29d5d70e90ce91b535a291fabb2924 to your computer and use it in GitHub Desktop.
[node js production ubuntu] #javascript #node #ubuntu #deploy

Install Node.js LTS, Yarn, and other deps

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install -y yarn nodejs nginx

Install pm2

yarn global add pm2
pm2 install pm2-logrotate
pm2 set pm2-logrotate:compress true
pm2 set pm2-logrotate:TZ "America/Sao_Paulo"

Make pm2 opens with system

pm2 startup systemd

Add pm2 app

# Start app
pm2 start --source-map-support npm --name "my-app" -- run "start:production"
# Save current app list
pm2 save 

Nginx Snippet

  # change the port for your app port
  location / {
    proxy_pass http://localhost:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment