This guide covers deploying the ChainPaye Payment Link API to various cloud platforms.
- Node.js 18+
- MongoDB Atlas connection string
- Environment variables configured
The application uses TypeScript and requires compilation before deployment:
npm install
npm run build
npm startRequired environment variables:
PORT=4000
NODE_ENV=production
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/database
TORONET_API_URL=https://api.toronet.com
TORONET_ADMIN_ADDRESS=your_admin_address
TORONET_ADMIN_PASSWORD=your_admin_password
ENCRYPTION_KEY_V1=your_encryption_key_v1
ENCRYPTION_KEY_V2=your_encryption_key_v2
# CORS Configuration (IMPORTANT for production)
CORS_ORIGIN=https://chainpaye.com,https://www.chainpaye.comDevelopment:
CORS_ORIGIN=*Production (REQUIRED):
CORS_ORIGIN=https://chainpaye.com,https://www.chainpaye.com,https://app.chainpaye.comCORS_ORIGIN=* in production. Always specify exact domains.
For detailed CORS configuration, see CORS_CONFIGURATION.md.
- Connect your GitHub repository
- Use the following settings:
- Build Command:
npm install && npm run build - Start Command:
npm start - Node Version: 18
- Build Command:
- Add environment variables in Render dashboard
- The
render.yamlfile is included for automatic configuration
- Install Heroku CLI
- Create new app:
heroku create your-app-name - Set environment variables:
heroku config:set MONGODB_URI=your_connection_string - Deploy:
git push heroku main - The
Procfileis included for automatic configuration
- Install Vercel CLI:
npm i -g vercel - Deploy:
vercel --prod - Configure environment variables in Vercel dashboard
- Connect GitHub repository
- Railway will auto-detect Node.js and use package.json scripts
- Add environment variables in Railway dashboard
dist/ # Compiled JavaScript files (generated)
src/ # TypeScript source files
├── server.ts # Main server entry point
├── app.ts # Express app configuration
├── config/ # Configuration files
├── controllers/ # Route controllers
├── middleware/ # Express middleware
├── models/ # MongoDB models
├── repositories/ # Data access layer
├── routes/ # API routes
├── services/ # Business logic
└── types/ # TypeScript type definitions
The API includes a health check endpoint:
- URL:
/api/v1/health - Method: GET
- Response: JSON with server status
Problem: Deployment platform looking for source file instead of compiled file.
Solutions:
- Ensure
npm run buildruns during deployment - Verify
package.jsonhas correct start script:"start": "node dist/server.js" - Check that TypeScript is in dependencies (not devDependencies)
- Ensure build command runs:
npm install && npm run build
Problem: MongoDB connection fails during deployment.
Solutions:
- Verify MONGODB_URI environment variable is set
- Check MongoDB Atlas IP whitelist (add 0.0.0.0/0 for cloud deployments)
- Ensure database user has proper permissions
- Test connection string locally first
Problem: Server not accessible after deployment.
Solutions:
- Use
process.env.PORTin server configuration - Don't hardcode port numbers
- Ensure platform-specific port configuration
Problem: TypeScript compilation fails during deployment.
Solutions:
- Move
typescriptfrom devDependencies to dependencies - Ensure all @types packages are available
- Check tsconfig.json configuration
- Verify Node.js version compatibility
- Enable gzip compression
- Use connection pooling for MongoDB
- Implement proper error handling
- Add request rate limiting
- Use environment-specific logging levels
- Never commit .env files
- Use strong encryption keys
- Implement proper CORS configuration
- Add request validation middleware
- Use HTTPS in production
- Implement proper authentication/authorization
- Set up health check monitoring
- Implement application logging
- Monitor database performance
- Track API response times
- Set up error alerting
- Use horizontal scaling for high traffic
- Implement database read replicas
- Add caching layer (Redis)
- Use CDN for static assets
- Implement load balancing