Skip to content

Latest commit

 

History

History
285 lines (229 loc) · 6.2 KB

File metadata and controls

285 lines (229 loc) · 6.2 KB

Deployment Guide

Table of Contents

  1. Prerequisites
  2. Database Setup
  3. Environment Configuration
  4. Deployment Options
  5. Post-Deployment
  6. Troubleshooting

Prerequisites

  • Node.js 20.x or higher
  • PostgreSQL database (Neon, AWS RDS, or any PostgreSQL provider)
  • Domain name (optional but recommended)
  • SSL certificate (for production)

Database Setup

Option 1: Neon Serverless (Recommended)

  1. Sign up at https://neon.tech
  2. Create a new project
  3. Copy the connection string (it looks like: postgresql://user:pass@ep-xxx.region.aws.neon.tech/dbname)
  4. The connection string will be your DATABASE_URL

Option 2: Other PostgreSQL Providers

  • AWS RDS
  • DigitalOcean Managed Database
  • Heroku Postgres
  • Self-hosted PostgreSQL

Ensure your database:

  • Supports WebSocket connections (or use connection pooling)
  • Has SSL enabled for production
  • Is accessible from your deployment environment

Environment Configuration

  1. Copy the example environment file:
cp .env.example .env
  1. Configure required variables:

Required Variables

DATABASE_URL=postgresql://user:password@host:5432/database
ENCRYPTION_SECRET=generate-a-strong-random-secret-here
NODE_ENV=production

Optional Variables (for full functionality)

AYRSHARE_API_KEY=your-ayrshare-api-key
AYRSHARE_PROFILE_KEY=your-profile-key
CLICKBANK_SECRET_KEY=your-clickbank-secret
PORT=5000

Security Note: Never commit .env files to version control!

Deployment Options

Option 1: VPS/Cloud Server (DigitalOcean, AWS EC2, etc.)

  1. SSH into your server
ssh user@your-server-ip
  1. Install Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
  1. Clone and setup
git clone https://github.com/al7566/Affiliateandsecurityapp.git
cd Affiliateandsecurityapp
npm install
  1. Configure environment
cp .env.example .env
nano .env  # Edit with your values
  1. Setup database
npm run db:push
  1. Build application
npm run build
  1. Start with PM2 (recommended)
sudo npm install -g pm2
pm2 start npm --name "affiliate-app" -- start
pm2 save
pm2 startup  # Follow the instructions
  1. Setup Nginx reverse proxy (optional but recommended)
server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:5000;
        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;
    }
}

Option 2: Docker Deployment

  1. Build Docker image
docker build -t affiliate-app .
  1. Run container
docker run -d \
  --name affiliate-app \
  -p 5000:5000 \
  -e DATABASE_URL="your-connection-string" \
  -e ENCRYPTION_SECRET="your-secret" \
  -e NODE_ENV=production \
  affiliate-app

Option 3: Platform as a Service

Heroku

heroku create your-app-name
heroku addons:create heroku-postgresql:mini
git push heroku main
heroku config:set ENCRYPTION_SECRET=your-secret
heroku config:set NODE_ENV=production

Railway

  1. Connect your GitHub repository
  2. Add PostgreSQL database
  3. Set environment variables
  4. Deploy automatically

Render

  1. Create new Web Service
  2. Connect repository
  3. Add PostgreSQL database
  4. Configure environment variables
  5. Deploy

Post-Deployment

1. Verify Application is Running

curl http://localhost:5000
# or
curl https://yourdomain.com

2. Initialize Database

The application will automatically seed default templates on first start.

3. Monitor Logs

# With PM2
pm2 logs affiliate-app

# With Docker
docker logs -f affiliate-app

# Direct
tail -f /var/log/your-app.log

4. Setup Monitoring

Consider using:

  • PM2 monitoring dashboard
  • New Relic
  • Datadog
  • Sentry for error tracking

Security Checklist

  • Environment variables are set correctly
  • Database uses SSL connection
  • ENCRYPTION_SECRET is strong and unique
  • Firewall configured (only allow ports 80, 443, 22)
  • SSL/TLS certificate installed (use Let's Encrypt)
  • Regular backups configured for database
  • Dependencies updated regularly (npm audit)
  • Application running as non-root user
  • Rate limiting configured (if needed)

Performance Optimization

  1. Enable compression (add to server if needed)
  2. Setup CDN for static assets
  3. Configure caching headers
  4. Database connection pooling (already configured)
  5. Monitor and scale based on traffic

Troubleshooting

Application won't start

  1. Check environment variables: printenv | grep DATABASE
  2. Verify database connection: psql $DATABASE_URL
  3. Check logs for errors
  4. Ensure port 5000 is available: lsof -i :5000

Database connection errors

  1. Verify DATABASE_URL is correct
  2. Check database is accessible from your server
  3. Ensure firewall allows database connections
  4. Verify SSL settings match your database provider

Build failures

  1. Clear node_modules: rm -rf node_modules && npm install
  2. Clear build cache: rm -rf dist
  3. Check Node.js version: node -v (should be 20.x+)

Performance issues

  1. Check database query performance
  2. Monitor memory usage: free -h
  3. Check CPU usage: top
  4. Scale horizontally if needed

Maintenance

Updates

git pull origin main
npm install
npm run build
pm2 restart affiliate-app

Database Migrations

npm run db:push

Backup Database

# For Neon/managed databases, use their backup tools
# For self-hosted:
pg_dump $DATABASE_URL > backup.sql

Support

For issues:

  1. Check logs first
  2. Review this guide
  3. Open GitHub issue with:
    • Error messages
    • Environment details
    • Steps to reproduce

Quick Reference

Start Development: npm run dev
Build: npm run build
Start Production: npm start
Type Check: npm run check
Database Push: npm run db:push

Default Port: 5000
Health Check: GET /api/health (if implemented)