Skip to content

Deploying Your NestJS App on DigitalOcean (or “How I Learned to Stop Worrying and Love Droplets”)

So you crushed Vercel ✅,

tamed AWS ✅,

and now someone whispers:

“Psst… DigitalOcean is fun.”

You shrug, take a sip of chai ☕, and mutter:

“Fine, I’ll sail the DO seas. But I’m bringing snacks.”

🧐 Why DigitalOcean?

  • Droplets = little virtual islands you control. 🏝️
  • App Platform = push code → magic happens ✨
  • Cheaper than AWS for tiny apps 💸
  • You can name your server something epic like nesty-mc-serverface.

Basically: DO is the playground for devs who like both control and fun.

⚡ Option 1: Droplet Deployment (“I like SSH, I like pain”)

1️⃣ Create Your Droplet

  • OS: Ubuntu 22.04 LTS
  • Size: $5/month (perfect for your “I’m testing, chill” budget)
  • SSH Keys: Add yours. No key? Cry a little, then create one. 🔑
  • Open ports: 22 (SSH), 80/443 (HTTP/HTTPS)

Bonus: Give it a funny hostname like nestinator-9000 🤖

2️⃣ SSH Into Your Droplet

bash
ssh root@YOUR_DROPLET_IP

Say hello to your tiny virtual island. 🏝️

3️⃣ Install Node.js, PM2, and Nginx

bash
sudo apt update
sudo apt install -y git curl nginx

# install nvm + Node LTS
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.nvm/nvm.sh
nvm install --lts

# install PM2 (keeps your app alive like a loyal puppy)
npm i -g pm2

4️⃣ Upload Your App

  • Option A: dist-only (fancy, fast, clean)
  • Option B: Full source (classic, slower, more drama)

Example for dist-only:

bash
mkdir -p /var/www/nestapp
cd /var/www/nestapp

# upload files via scp/rsync or git clone
# include: dist/, package.json, .env

npm ci --omit=dev

5️⃣ Start NestJS With PM2

bash
pm2 start dist/main.js --name nestapp --watch
pm2 save
pm2 startup systemd

Your app now runs forever — like that one meme that never dies. 💀

6️⃣ Nginx Reverse Proxy (Because 127.0.0.1 is boring)

nginx
server {
    listen 80;
    server_name yourdomain.com;

    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;
    }
}

Enable + reload:

bash
sudo ln -s /etc/nginx/sites-available/nestapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

7️⃣ Free HTTPS (because humans like security)

bash
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com

Your site is now secure enough to sleep peacefully at night. 🛌

⚡ Option 2: DigitalOcean App Platform (“The Lazy Wizard”)

  1. Push your NestJS repo to GitHub.
  2. Log in to DigitalOcean → AppsCreate App.
  3. Connect GitHub repo, choose branch, and set build command:
bash
npm ci
npm run build
  1. Run command:
bash
node dist/main.js
  1. DigitalOcean gives you a URL like: https://nestapp.onrender.com
  2. Click deploy, wait 2–3 minutes, sip chai 🍵 → boom! 🎉

🎯 TL;DR — DigitalOcean Cheat Sheet

MethodProsCons
Droplet + PM2 + NginxFull control, production-readyManual setup, tiny pain
App PlatformPush code → deploy, almost magicSlightly more expensive

✅ Pro Tip: Health Endpoint

Always have a /health endpoint so monitoring tools or load balancers don’t cry:

ts
@Get('health')
health() {
  return { ok: true, ts: new Date().toISOString() };
}

🏁 Summary

  • Droplets → you’re captain, you decide. ⚓
  • App Platform → AWS hands you a magic wand. ✨

Either way, your NestJS app is live, secure, and ready to flex:

“I deployed to DigitalOcean. Yes, I am cooler than you.” 😎

Built by noobs, for noobs, with love 💻❤️