Setup EC2 / Droplet or any virtual machine by any cloud provider

🔐 Create SSH Key for Github

ssh-keygen -t ed25519 -C "[email protected]"
cat /home/ubuntu/.ssh/id_ed25519.pub 

Add the SSH key to Github and clone the repo

🏁 Install NVM, Node, NPM & PNPM

curl -o- <https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh> | bash
source ~/.bashrc
nvm list-remote
nvm i <node-version>
nvm ls
curl -fsSL <https://get.pnpm.io/install.sh> | sh -
source /home/ubuntu/.bashrc

Install all packages and generate the build file

🔄 Setup Nginx reverse Proxy

sudo nano /etc/nginx/sites-available/yourdomain.com

Paste the nginx config, also setup the ip address in your DNS with your domain name

server {
  listen 80;
  server_name yoururl.in;
  location / {
    proxy_pass <http://localhost: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;
  }
}

Now we confirm our nginx setup

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo service nginx restart

🏎️ Setup and Validate PM2

pm2 start npm --name "your-application-name" -- start
pm2 status
pm2 logs
pm2 startup

🪪 Enable SSL Certificates

sudo apt install snapd -y
sudo snap install core && sudo snap refresh core
sudo snap install --classic certbot
sudo certbot --nginx -d yourdomain.com
sudo certbot renew --dry-run

<aside> ✅

and Voila! you’re good to go.

</aside>

References: