Deploying a Feathers application to production requires careful configuration, security hardening, and performance optimization. This guide covers best practices for production deployments.
Pre-Deployment Checklist
Before deploying to production, ensure you’ve completed these critical steps:
Production Configuration
Environment-Specific Config
Create config/production.json with production settings:
Never commit config/production.json if it contains secrets. Use environment variables for sensitive data.
Environment Variables Mapping
Use config/custom-environment-variables.json to map environment variables:
Application Setup
Server Startup
Your main entry point should properly initialize the application:
Graceful Shutdown
Implement graceful shutdown to cleanly close connections:
Security Best Practices
1. Authentication Secret
Use a strong, random secret for JWT signing:
2. CORS Configuration
Restrict origins to your actual domains:
3. Rate Limiting
Protect against brute force attacks:
5. Data Validation
Always validate and sanitize user input:
Database Configuration
Connection Pooling
Configure appropriate connection pool settings:
MongoDB Connection
Database Cleanup on Shutdown
1. Enable Compression
Set reasonable pagination limits:
3. Use Caching
Implement caching for frequently accessed data:
4. Database Indexes
Ensure proper indexes on frequently queried fields:
Docker
Create a Dockerfile:
Create docker-compose.yml for local production testing:
Heroku
Create a Procfile:
Set environment variables:
AWS (Elastic Beanstalk)
Create .ebextensions/nodecommand.config:
Create .do/app.yaml:
Monitoring and Logging
Structured Logging
Use Winston or Pino for production logging:
Error Tracking
Integrate error tracking (Sentry, Rollbar, etc.):
Health Checks
Implement health check endpoints:
SSL/TLS Configuration
Using HTTPS
For production, use HTTPS:
Reverse Proxy (Recommended)
In most cases, use a reverse proxy like Nginx:
Scaling Considerations
Horizontal Scaling
When running multiple instances, use a message queue for real-time events:
Configure Redis for pub/sub:
Process Management
Use PM2 for process management:
Create ecosystem.config.js:
Start with PM2:
Continuous Deployment
GitHub Actions Example
Post-Deployment
After deployment:
- Verify health checks - Ensure the application is responding
- Check logs - Monitor for errors or warnings
- Test critical paths - Verify authentication, key services
- Monitor performance - Watch CPU, memory, response times
- Set up alerts - Configure monitoring alerts