Skip to content

Instantly share code, notes, and snippets.

@bala-codes
Created February 28, 2022 06:11
Show Gist options
  • Save bala-codes/52c24b246a4f03bfa9788732d5550108 to your computer and use it in GitHub Desktop.
Save bala-codes/52c24b246a4f03bfa9788732d5550108 to your computer and use it in GitHub Desktop.
Deploy Node.js based application in EC2 ubuntu using PM2
1 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
2 . ~/.nvm/nvm.sh
3 nvm install v16.6.1
4 node -e "console.log('Running Node.js ' + process.version)"
5 sudo apt-get update
6 sudo apt-get upgrade
7 git clone --branch dev https://github.com/Zevigo-Solutions/nhg-hr.git
8 cd nhg-hr/
9 node app.js
10 clear
11 sudo apt install nginx
12 cd /etc/nginx/sites-enabled
13 sudo vim default
14 sudo service nginx restart
15 npm install pm2 -g
16 cd
17 cd nhg-hr/
18 pm2 start app.js
19 pm2 startup
20 sudo env PATH=$PATH:/home/ubuntu/.nvm/versions/node/v16.6.1/bin /home/ubuntu/.nvm/versions/node/v16.6.1/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
21 pm2 save
22 pm2 status
23 sudo reboot
24 sudo apt update
25 sudo apt install snapd
26 sudo snap install hello-world
27 sudo snap install core; sudo snap refresh core
28 sudo snap install --classic certbot
29 sudo ln -s /snap/bin/certbot /usr/bin/certbot
30 sudo certbot --nginx
31 sudo certbot renew --dry-run
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /usr/share/nginx/html;
location / {
proxy_pass http://127.0.0.1:3000;
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