- Prerequisites
- Database Setup
- Environment Configuration
- Deployment Options
- Post-Deployment
- Troubleshooting
- Node.js 20.x or higher
- PostgreSQL database (Neon, AWS RDS, or any PostgreSQL provider)
- Domain name (optional but recommended)
- SSL certificate (for production)
- Sign up at https://neon.tech
- Create a new project
- Copy the connection string (it looks like:
postgresql://user:pass@ep-xxx.region.aws.neon.tech/dbname) - The connection string will be your
DATABASE_URL
- 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
- Copy the example environment file:
cp .env.example .env- Configure required variables:
DATABASE_URL=postgresql://user:password@host:5432/database
ENCRYPTION_SECRET=generate-a-strong-random-secret-here
NODE_ENV=productionAYRSHARE_API_KEY=your-ayrshare-api-key
AYRSHARE_PROFILE_KEY=your-profile-key
CLICKBANK_SECRET_KEY=your-clickbank-secret
PORT=5000Security Note: Never commit .env files to version control!
- SSH into your server
ssh user@your-server-ip- Install Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs- Clone and setup
git clone https://github.com/al7566/Affiliateandsecurityapp.git
cd Affiliateandsecurityapp
npm install- Configure environment
cp .env.example .env
nano .env # Edit with your values- Setup database
npm run db:push- Build application
npm run build- Start with PM2 (recommended)
sudo npm install -g pm2
pm2 start npm --name "affiliate-app" -- start
pm2 save
pm2 startup # Follow the instructions- 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;
}
}- Build Docker image
docker build -t affiliate-app .- 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-appheroku 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- Connect your GitHub repository
- Add PostgreSQL database
- Set environment variables
- Deploy automatically
- Create new Web Service
- Connect repository
- Add PostgreSQL database
- Configure environment variables
- Deploy
curl http://localhost:5000
# or
curl https://yourdomain.comThe application will automatically seed default templates on first start.
# With PM2
pm2 logs affiliate-app
# With Docker
docker logs -f affiliate-app
# Direct
tail -f /var/log/your-app.logConsider using:
- PM2 monitoring dashboard
- New Relic
- Datadog
- Sentry for error tracking
- 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)
- Enable compression (add to server if needed)
- Setup CDN for static assets
- Configure caching headers
- Database connection pooling (already configured)
- Monitor and scale based on traffic
- Check environment variables:
printenv | grep DATABASE - Verify database connection:
psql $DATABASE_URL - Check logs for errors
- Ensure port 5000 is available:
lsof -i :5000
- Verify DATABASE_URL is correct
- Check database is accessible from your server
- Ensure firewall allows database connections
- Verify SSL settings match your database provider
- Clear node_modules:
rm -rf node_modules && npm install - Clear build cache:
rm -rf dist - Check Node.js version:
node -v(should be 20.x+)
- Check database query performance
- Monitor memory usage:
free -h - Check CPU usage:
top - Scale horizontally if needed
git pull origin main
npm install
npm run build
pm2 restart affiliate-appnpm run db:push# For Neon/managed databases, use their backup tools
# For self-hosted:
pg_dump $DATABASE_URL > backup.sqlFor issues:
- Check logs first
- Review this guide
- Open GitHub issue with:
- Error messages
- Environment details
- Steps to reproduce
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)