DEV Community

天涯
天涯

Posted on

5 Deployment Problems Every Beginner Faces (And How to Fix Them)

5 Deployment Problems Every Beginner Faces (And How to Fix Them)

based on my mentoring, these are the issues I see over and over again.

Problem #1: "Works on My Machine"

Why it happens:

  • Missing environment variables
  • Port conflicts
  • Node version mismatch

Solution:

# Check Node version
node --version

# Check port usage
netstat -tulpn | grep :3000

# Set environment variables
cp .env.example .env
nano .env
Enter fullscreen mode Exit fullscreen mode

Problem #2: "Can't Access My App"

Firewall. It's always the firewall.

Solution:

# Open necessary ports
ufw allow 80
ufw allow 443
ufw allow 22

# Enable firewall
ufw enable

# Check status
ufw status
Enter fullscreen mode Exit fullscreen mode

Problem #3: "App Dies After Server Restart"

You need a process manager.

Solution:

# Install PM2
npm install -g pm2

# Start your app
pm2 start app.js

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

Problem #4: "Which Cloud Provider?"

Stop overthinking it.

Just use DigitalOcean

Why:

  • Simplest UI
  • Best docs for beginners
  • $200 free credit

Sign up here

Problem #5: "Too Expensive"

It's not. Really.

  • Minimum: $6/month
  • New users: $200 credit
  • That's months of free hosting

Deployment Checklist

Before deploying:

  • [ ] Code pushed to Git
  • [ ] Environment variables documented
  • [ ] Tests passing

Server setup:

  • [ ] Create droplet
  • [ ] Configure SSH key
  • [ ] Update system
  • [ ] Install Node.js
  • [ ] Configure firewall

App deployment:

  • [ ] Clone code
  • [ ] Install dependencies
  • [ ] Set environment variables
  • [ ] Start app
  • [ ] Configure PM2

Verification:

  • [ ] Test via IP address
  • [ ] Check logs
  • [ ] Test server restart

One-Command Deploy Script

Save this, use it every time:

#!/bin/bash
# One-command deployment

# Update system
apt update && apt upgrade -y

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

# Install PM2
npm install -g pm2

# Clone and deploy
git clone YOUR_REPO
cd YOUR_PROJECT
npm install
pm2 start app.js
pm2 startup
pm2 save

# Firewall
ufw allow 80
ufw allow 443
ufw allow 22
ufw enable

echo "Deployment complete!"
Enter fullscreen mode Exit fullscreen mode

Common Errors

Permission denied

sudo npm install -g pm2
Enter fullscreen mode Exit fullscreen mode

Port already in use

lsof -i :3000
kill -9 PID
Enter fullscreen mode Exit fullscreen mode

💡 Use the link above for $200 free credit. All my students use DigitalOcean — it just works.

Top comments (0)