Skip to main content

Pre-Deployment Checklist

Before deploying to production, ensure you complete all items in this checklist.

Environment Configuration

  • Set NODE_ENV=production in environment variables
  • Generate secure JWT secrets (minimum 32 characters)
  • Configure MongoDB connection string (Atlas or self-hosted)
  • Set up TRON mainnet endpoint (https://api.trongrid.io)
  • Configure merchant wallet address
  • Set correct frontend/client URLs for CORS
  • Review all environment variables (see Environment Variables)

Security Hardening

  • Enable HTTPS/TLS for all connections
  • Set secure: true for cookie options in production
  • Configure rate limiting for API endpoints
  • Enable Helmet.js security headers
  • Implement HPP (HTTP Parameter Pollution) protection
  • Review and restrict CORS origins
  • Ensure sensitive data is not logged
  • Set up firewall rules to restrict database access

Database

  • Set up MongoDB Atlas with authentication
  • Configure database backups and retention policy
  • Create indexes for frequently queried fields
  • Set up connection pooling
  • Enable MongoDB encryption at rest
  • Configure replica sets for high availability

Wallet Security

Never store private keys in your codebase or environment variables. Use a secure key management system.
  • Store admin wallet private key in secure vault (e.g., AWS Secrets Manager, HashiCorp Vault)
  • Implement wallet backup and recovery procedures
  • Use hardware wallets for high-value merchant accounts
  • Test refund functionality on testnet before production
  • Monitor wallet balance and set up low-balance alerts

TRON Network

  • Switch from Nile testnet to TRON mainnet
  • Test transaction listener with mainnet configuration
  • Verify transaction confirmation thresholds
  • Set up monitoring for failed transactions
  • Configure appropriate network fees

Monitoring & Logging

  • Set up application logging (Winston, Pino, etc.)
  • Configure error tracking (Sentry, Rollbar, etc.)
  • Implement uptime monitoring (Pingdom, UptimeRobot)
  • Set up alerts for critical errors
  • Monitor API response times and performance
  • Track transaction confirmation delays
  • Monitor database performance and query times

Performance Optimization

  • Enable gzip compression for API responses
  • Implement caching for frequently accessed data
  • Optimize database queries and add indexes
  • Set up CDN for static assets (if applicable)
  • Configure appropriate connection timeouts
  • Load test API endpoints to determine capacity

Deployment Infrastructure

  • Use a process manager (PM2, systemd) for Node.js
  • Configure auto-restart on crashes
  • Set up load balancing for multiple instances
  • Enable graceful shutdown handling
  • Configure appropriate memory limits
  • Set up CI/CD pipeline for automated deployments

Testing

  • Run all unit tests and ensure they pass
  • Perform integration testing with frontend
  • Test Socket.io real-time notifications
  • Verify transaction listener functionality
  • Test admin panel operations
  • Perform security penetration testing
  • Load test critical endpoints (orders, payments)

Documentation

  • Document API endpoints and authentication
  • Create runbooks for common operations
  • Document emergency procedures (refunds, rollbacks)
  • Maintain architecture diagrams
  • Document disaster recovery procedures

Deployment Steps

1. Server Setup

# Update system packages
sudo apt update && sudo apt upgrade -y

# Install Node.js (v16+)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Install PM2 globally
sudo npm install -g pm2

2. Application Deployment

# Clone repository
git clone <repository-url>
cd crypto-shop-backend

# Install dependencies
npm install --production

# Create .env file
cp .env.example .env
nano .env  # Configure production variables

3. Start Application with PM2

# Start application
pm2 start src/index.js --name crypto-shop-backend

# Save PM2 configuration
pm2 save

# Enable startup script
pm2 startup

4. Configure Nginx (Optional)

server {
    listen 80;
    server_name api.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_cache_bypass $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

5. SSL Certificate Setup

# Install Certbot
sudo apt install certbot python3-certbot-nginx

# Obtain SSL certificate
sudo certbot --nginx -d api.yourdomain.com

Post-Deployment

Verification

  • Verify API health endpoint is responding
  • Test user registration and login
  • Create a test order and payment
  • Verify transaction listener is running
  • Check Socket.io connections
  • Test admin panel functionality
  • Verify Swagger documentation is accessible

Monitoring Setup

# Monitor application logs
pm2 logs crypto-shop-backend

# Monitor process status
pm2 status

# Monitor system resources
pm2 monit

Backup Configuration

Set up automated MongoDB backups:
# Create backup script
#!/bin/bash
DATE=$(date +"%Y%m%d_%H%M%S")
mongodump --uri="$MONGODB_URI" --out=/backups/mongo_$DATE

# Compress backup
tar -czf /backups/mongo_$DATE.tar.gz /backups/mongo_$DATE
rm -rf /backups/mongo_$DATE

# Delete backups older than 30 days
find /backups -name "mongo_*.tar.gz" -mtime +30 -delete
Add to crontab for daily backups:
0 2 * * * /path/to/backup-script.sh

Common Issues

Application Won’t Start

  • Check environment variables are correctly set
  • Verify MongoDB connection string
  • Check Node.js version (requires v16+)
  • Review application logs for errors

Transaction Listener Not Working

  • Verify TRON_NETWORK is set to mainnet URL
  • Check network connectivity to TronGrid
  • Ensure merchant wallet address is correct
  • Review transaction listener logs

Socket.io Connection Failures

  • Verify CORS configuration includes frontend URL
  • Check WebSocket support on reverse proxy
  • Ensure firewall allows WebSocket connections

Rollback Procedure

# Stop current version
pm2 stop crypto-shop-backend

# Checkout previous version
git checkout <previous-commit-hash>

# Install dependencies
npm install --production

# Restart application
pm2 restart crypto-shop-backend

Support

For technical support or deployment assistance, contact: Pedro Luis Ramos Calla
Project Developer

Build docs developers (and LLMs) love