Pre-Deployment Checklist
Before deploying to production, ensure you have:- MongoDB database set up (local or MongoDB Atlas)
- Production environment variables configured
- Domain name configured (if applicable)
- SSL/TLS certificates ready
- Backend and frontend code tested locally
- All dependencies up to date and audited for security
Frontend Production Build
Configure production environment variables
Create a Replace
.env.production file in the frontend directory:https://api.yourdomain.com with your actual backend API URL.Build the frontend
Navigate to the frontend directory and run the build command:This creates an optimized production build in the
dist directory.Test the production build locally
Preview the production build before deploying:This serves the built files locally so you can test them.
Frontend Deployment Examples
Vercel Deployment
Netlify Deployment
Nginx Configuration
For self-hosted deployments with Nginx:Backend Production Setup
Configure production environment variables
Create a
.env file on your production server with production values:Install production dependencies
On your production server, navigate to the backend directory and install dependencies:The
--production flag skips development dependencies.Set up process manager
Use a process manager to keep your application running and restart it on crashes.Option 1: PM2 (Recommended)Option 2: systemd service
Create Enable and start the service:
/etc/systemd/system/smartshelf.service:Configure reverse proxy
Set up Nginx as a reverse proxy to handle SSL and forward requests to your Node.js backend.Create Enable the site:
/etc/nginx/sites-available/smartshelf-api:Backend Deployment Platforms
Heroku
Railway
- Sign up at Railway.app
- Click “New Project” → “Deploy from GitHub repo”
- Select your repository and backend directory
- Add environment variables in the “Variables” tab
- Railway automatically detects Node.js and deploys
DigitalOcean App Platform
- Create account at DigitalOcean
- Click “Create App” and connect your GitHub repository
- Select the backend directory
- Configure environment variables
- Choose your plan and deploy
Environment Variable Management
Secure Storage Options
-
Platform-specific environment variables
- Use your hosting platform’s environment variable management (Heroku Config Vars, Vercel Environment Variables, etc.)
-
Secret management services
- AWS Secrets Manager - Managed secret storage for AWS deployments
- HashiCorp Vault - Enterprise secret management
- Azure Key Vault - Microsoft’s secret management solution
-
Environment files on server
- Store
.envfile on server with restricted permissions:
- Store
Environment Variable Validation
Add validation to ensure all required environment variables are present:MongoDB Production Configuration
MongoDB Atlas Production Setup
Upgrade to production tier
Free tier (M0) is suitable for development, but consider upgrading for production:
- M10 - Recommended minimum for production
- M20+ - For higher traffic applications
Enable automated backups
- Go to your cluster in MongoDB Atlas
- Navigate to “Backup” tab
- Enable “Cloud Backup”
- Configure backup schedule and retention policy
Configure IP allowlist
Replace “Allow access from anywhere” with specific IP addresses:
- Go to “Network Access”
- Remove 0.0.0.0/0 entry
- Add your production server IPs only
Enable monitoring and alerts
- Go to “Alerts” in Atlas
- Set up alerts for:
- High connection count
- CPU usage
- Disk usage
- Query performance issues
Self-Hosted MongoDB Production
If running your own MongoDB server:-
Enable authentication:
-
Enable SSL/TLS:
-
Configure firewall:
-
Set up replication:
- Use replica sets for high availability
- Minimum 3-member replica set recommended
Security Best Practices
Application Security
-
Use HTTPS everywhere
- Enable SSL/TLS for all connections
- Redirect HTTP to HTTPS
- Use HSTS headers
-
Implement rate limiting
-
Enable security headers
-
Validate and sanitize input
- Use validation libraries (express-validator, joi)
- Sanitize user input to prevent injection attacks
- Implement proper error handling
-
Keep dependencies updated
Database Security
-
Use strong passwords
- Minimum 16 characters
- Mix of uppercase, lowercase, numbers, symbols
- Use password generator
-
Principle of least privilege
- Grant minimum necessary permissions
- Use separate database users for different services
-
Enable encryption at rest
- MongoDB Atlas encrypts data at rest by default
- For self-hosted, enable encryption
-
Monitor database access
- Enable audit logging
- Review access logs regularly
- Set up alerts for suspicious activity
API Security
-
Implement proper authentication
- Use strong JWT secrets
- Set reasonable token expiration times
- Implement token refresh mechanism
-
Configure CORS properly
-
Protect sensitive endpoints
- Require authentication for all protected routes
- Implement role-based access control
- Log access to sensitive operations
Monitoring and Logging
Application Monitoring
-
PM2 Monitoring
-
Application Performance Monitoring (APM)
- New Relic - Full-stack monitoring
- Datadog - Infrastructure and APM
- Sentry - Error tracking and monitoring
Logging Best Practices
Performance Optimization
-
Enable caching
- Use Redis for session storage and caching
- Implement API response caching
- Enable browser caching for static assets
-
Database optimization
- Create indexes for frequently queried fields
- Use connection pooling
- Implement query result caching
-
Frontend optimization
- Enable gzip/brotli compression
- Implement lazy loading for routes
- Optimize images and assets
- Use CDN for static assets
-
Load balancing
- Use multiple backend instances
- Implement load balancer (Nginx, HAProxy)
- Scale horizontally as traffic grows
Backup and Disaster Recovery
-
Automated backups
- Daily automated backups (MongoDB Atlas provides this)
- Store backups in multiple locations
- Test restore procedures regularly
-
Version control
- Tag releases in Git
- Maintain changelog
- Keep deployment documentation updated
-
Rollback strategy
- Keep previous versions available
- Document rollback procedures
- Test rollback in staging environment
For more configuration details, see Environment Variables and Database Setup guides.