Facebook Pixel

Deploying DevTinder to Production AWS, Nginx, and PM2 Setup Guide

Learn how to deploy the DevTinder project to production on AWS EC2 with Nginx as a reverse proxy, PM2 for process management, and environment variable configuration.

Deploying DevTinder to Production

Deploying DevTinder involves setting up an AWS EC2 instance, configuring Nginx as a reverse proxy, using PM2 for Node.js process management, and securing the app with environment variables and SSL.

Step 1: Launch an AWS EC2 Instance

  1. Go to AWS Console → EC2 → Launch Instance
  2. Choose Ubuntu Server 22.04 LTS
  3. Select t2.micro (free tier) or larger for production
  4. Configure security group:
    • SSH (port 22) your IP
    • HTTP (port 80) anywhere
    • HTTPS (port 443) anywhere
    • Custom TCP (port 3000) your IP (for direct API access during testing)
  5. Launch and download the key pair (.pem file)

Step 2: Connect to the Instance

ssh -i your-key.pem ubuntu@your-ec2-public-ip

Step 3: Install Node.js and Required Software

# Update packages sudo apt update && sudo apt upgrade -y # Install Node.js 20 curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs # Install PM2 globally sudo npm install -g pm2 # Install Nginx sudo apt install -y nginx # Install Git sudo apt install -y git

Step 4: Clone and Set Up the Backend

cd /home/ubuntu git clone https://github.com/yourusername/devtinder-backend.git cd devtinder-backend npm install

Create the production .env file:

cp .env.example .env nano .env
PORT=3000 MONGODB_URI=mongodb+srv://your-atlas-connection-string JWT_SECRET=your_production_secret NODE_ENV=production CLIENT_URL=https://yourdomain.com

Step 5: Start the App with PM2

pm2 start src/server.js --name devtinder-api pm2 save pm2 startup

PM2 keeps the Node.js process running, restarts on crash, and starts on system boot.

Step 6: Configure Nginx as Reverse Proxy

sudo nano /etc/nginx/sites-available/devtinder
server { listen 80; server_name 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; } }

The Upgrade and Connection headers are critical for Socket.io WebSocket support.

sudo ln -s /etc/nginx/sites-available/devtinder /etc/nginx/sites-enabled/ sudo rm /etc/nginx/sites-enabled/default sudo nginx -t sudo systemctl restart nginx

Step 7: Deploy the Frontend

The frontend can be deployed separately to Vercel, Netlify, or the same EC2 instance.

To Vercel:

npm install -g vercel cd devtinder-frontend vercel

Set the environment variable VITE_API_URL=https://yourdomain.com/api in Vercel.

Step 8: Add SSL with Let's Encrypt

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

This automatically configures Nginx for HTTPS and sets up auto-renewal.

Step 9: Verify the Deployment

  • Visit https://yourdomain.com should show the API response
  • Test signup and login
  • Test the frontend at the Vercel URL
  • Check PM2 logs: pm2 logs devtinder-api
  • Check Nginx logs: sudo tail -f /var/log/nginx/error.log

The Takeaway

Deploying DevTinder to production involves: launching an AWS EC2 instance, installing Node.js and PM2, cloning the backend, configuring environment variables, starting with PM2, setting up Nginx as a reverse proxy (with WebSocket support for Socket.io), deploying the frontend to Vercel, and adding SSL with Let's Encrypt. PM2 ensures the app restarts on crash, and Nginx handles routing and SSL termination.

Launch an Ubuntu EC2 instance, install Node.js and PM2, clone the backend repo, configure .env, start with pm2 start, configure Nginx as a reverse proxy, and add SSL with Let's Encrypt. The frontend can be deployed to Vercel separately.

PM2 keeps the Node.js process running, automatically restarts on crash, starts on system boot with pm2 startup, and provides log management. Without PM2, the app would stop when the SSH session ends or on an unhandled error.

Nginx listens on port 80 (and 443 with SSL) and proxies requests to the Node.js app on port 3000. It handles SSL termination, static file serving, and WebSocket upgrades for Socket.io. The Upgrade and Connection headers are critical for WebSocket support.

Install certbot and the Nginx plugin (sudo apt install certbot python3-certbot-nginx), then run sudo certbot --nginx -d yourdomain.com. Certbot automatically configures Nginx for HTTPS and sets up auto-renewal.

The frontend can be deployed to Vercel (npm install -g vercel, then vercel in the frontend directory), Netlify, or the same EC2 instance. Set the VITE_API_URL environment variable to point to the backend domain (https://yourdomain.com/api).

Ready to master Node.js completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.