DEV Community

天涯
天涯

Posted on

Deploy a Node.js App to DigitalOcean in 5 Minutes

Deploy a Node.js App to DigitalOcean in 5 Minutes

Here's a story: last year around this time I deployed an app, celebrated, went to bed. Next morning? Site was down. Server had restarted overnight.

Today I'm sharing my complete deployment workflow. No BS, just what works.

My Setup

I'm currently running 7 production apps using this exact setup. It's stable, affordable, and low-maintenance.

Why DigitalOcean?

I've tried AWS, Heroku, Vercel, Render, and a dozen others. DigitalOcean became my go-to. Not because it's the cheapest (it's not), but because:

  1. Simple UI
    Took me 5 minutes to figure out on day one. Compare that to AWS's maze of services.

  2. Solid docs
    When something breaks, their docs actually help. Novel concept, I know.

  3. Transparent pricing
    $6/month means $6/month. No surprise bills.

Sign up for DigitalOcean — new users get $200 credit, which lasts months.

Complete Deployment Steps

1. Create a Droplet

Click "Create" → "Droplets". My standard config:

Image: Ubuntu 22.04 LTS
Plan: Basic $6/month (1GB RAM)
Datacenter: Pick closest to your users
SSH Key: Set this up (way more secure than passwords)
Enter fullscreen mode Exit fullscreen mode

Hit create. Takes about 60 seconds.

2. SSH Into Your Server

ssh root@your_server_ip
Enter fullscreen mode Exit fullscreen mode

3. Install Node.js

I use this script every time:

# Update system
apt update && apt upgrade -y

# Install Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs

# Install PM2 (process manager)
npm install -g pm2

# Verify
node --version
Enter fullscreen mode Exit fullscreen mode

4. Deploy Your App

# Clone your repo
git clone your-repo-url
cd your-project

# Install dependencies
npm install

# Start with PM2
pm2 start app.js --name "my-app"

# Enable auto-restart on reboot
pm2 startup
pm2 save
Enter fullscreen mode Exit fullscreen mode

5. Configure Firewall

Don't skip this. I spent 2 hours debugging once because I forgot:

ufw allow 80
ufw allow 443
ufw allow 22
ufw enable
Enter fullscreen mode Exit fullscreen mode

Mistakes I Made (So You Don't Have To)

Mistake #1: Choosing the cheapest plan
I tried the $2.5/month droplet to save money. It was painfully slow. The $6 plan is worth every penny.

Mistake #2: No backups
Accidentally dropped my database once. Luckily had auto-backups enabled. Now I backup daily.

Mistake #3: No monitoring
Server went down for 6 hours before I noticed. Now I use UptimeRobot (free) to get alerts.

Cost Breakdown

My current setup:

  • DigitalOcean: $6/month
  • Domain: $12/year (~$1/month)
  • SSL: Free (Let's Encrypt)

Total: $7/month

Way cheaper than managed platforms, and you have full control.

What's Next?

Once deployed, you can add:

  • Custom domain + SSL
  • Nginx reverse proxy
  • CI/CD pipeline

I'll cover these in future posts.


💡 Use the link above to get $200 in free credits. I use DO for all my projects — it's been rock solid.

Questions? Drop them in the comments 👇

Top comments (0)