Deployment

Deploy MatchNest to a production Linux server using PM2 and Nginx.

Prerequisites

  • Linux server (Ubuntu 20.04+ or Rocky Linux 8+)
  • Node.js 18+ installed
  • Nginx installed
  • PM2 process manager: npm install -g pm2
  • A domain name pointing to your server

Step 1 — Upload Files

# Option A: Git clone (recommended)
cd /www/wwwroot/yourdomain.com
git clone https://github.com/your-repo/matchnest.git .

# Option B: SCP from local
scp -r ./matchnest user@your-server:/www/wwwroot/yourdomain.com/

Step 2 — Install & Build

cd /www/wwwroot/yourdomain.com

# Install production dependencies
npm install --production=false

# Configure environment
cp .env.example .env
nano .env   # Set your production values

# Set up database (use PostgreSQL in production)
npm run db:push
npm run db:seed

# Build for production
npm run build

Step 3 — Configure Environment for Production

# .env (production)
DATABASE_URL="file:./prod.db"
JWT_SECRET="use-a-long-random-64-char-secret"
NEXTAUTH_URL="https://yourdomain.com"
NODE_ENV="production"
PORT=3000

Step 4 — Start with PM2

# Start the app
pm2 start npm --name "matchnest" -- start

# Save PM2 process list (auto-restart on reboot)
pm2 save
pm2 startup

# View logs
pm2 logs matchnest

Step 5 — Configure Nginx Reverse Proxy

# /etc/nginx/sites-available/yourdomain.com
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    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_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

# Enable the site
ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

Step 6 — SSL Certificate

# Install Certbot
apt install certbot python3-certbot-nginx

# Get certificate
certbot --nginx -d yourdomain.com -d www.yourdomain.com

# Auto-renewal is set up automatically

Switching to PostgreSQL (Recommended for Production)

SQLite works fine for small deployments but PostgreSQL is recommended for production traffic.

# Install PostgreSQL
apt install postgresql postgresql-contrib

# Create database
sudo -u postgres createdb matchnest
sudo -u postgres createuser matchnest_user

# Update .env
DATABASE_URL="postgresql://matchnest_user:password@localhost:5432/matchnest"

# Update prisma/schema.prisma datasource
# provider = "postgresql"   (instead of "sqlite")

# Re-push schema
npm run db:push

Updating MatchNest

cd /www/wwwroot/yourdomain.com
git pull origin main
npm install
npm run db:push
npm run build
pm2 restart matchnest