Configuration Guide
CUIDO Backend uses environment variables for configuration. This guide documents all available options with detailed explanations and examples.Environment File Setup
Create a.env file in the project root:
Core Configuration
Server Settings
The port number on which the server will listen for incoming requests.Common ports:
3000- Default development8080- Alternative development80- HTTP production (requires privileges)443- HTTPS production (requires privileges)
The application environment mode. Affects logging, error handling, and security settings.Valid values:
development- Verbose logging, detailed errors, hot reloadproduction- Minimal logging, sanitized errors, optimizationstest- Test mode, in-memory database, mocked services
Database Configuration
MongoDB Connection
MongoDB connection string. Supports both local and cloud (Atlas) connections.Connection string components:
mongodb://ormongodb+srv://- Protocolusername:password@- Credentials (optional for local)localhost:27017- Host and port/claude-prompt-db- Database name?options- Connection options
The database connection uses these Mongoose options:
maxPoolSize: 10- Maximum 10 concurrent connectionsserverSelectionTimeoutMS: 5000- 5 second timeoutsocketTimeoutMS: 45000- 45 second socket timeout
Authentication & Security
JWT Configuration
Secret key for signing and verifying JSON Web Tokens. Must be kept secure.Best practices:
- Minimum 32 characters
- Mix of letters, numbers, and symbols
- Generate with:
openssl rand -base64 32 - Different for each environment
- Never reuse across projects
Token expiration time. Uses vercel/ms format.Valid formats:
60- 60 seconds5m- 5 minutes2h- 2 hours7d- 7 days30d- 30 days
src/services/authService.js:9 uses:
src/services/authService.js:20:
Anthropic Claude AI
API Configuration
Your Anthropic API key for Claude AI integration. Get it from console.anthropic.com.Key format validation:
- Must start with
sk-ant- - Validated on server startup (
server.js:31-38) - Connection tested before server starts
The Claude model to use for completions. Different models offer different performance/cost tradeoffs.Available models:
| Model | Best For | Speed | Cost |
|---|---|---|---|
claude-3-opus-20240229 | Complex tasks, highest accuracy | Slower | Highest |
claude-3-sonnet-20240229 | Balanced (recommended) | Medium | Medium |
claude-3-haiku-20240307 | Simple tasks, high volume | Fastest | Lowest |
server.js:31-46):
CORS & Security
Cross-Origin Resource Sharing
Comma-separated list of allowed origins for CORS.Implementation (
src/app.js:51):Comma-separated list of allowed origins for Socket.IO connections.Implementation (
server.js:65):Rate Limiting
Global Rate Limits
Time window for rate limiting in milliseconds.Common values:
60000- 1 minute300000- 5 minutes900000- 15 minutes (default)3600000- 1 hour
Maximum number of requests allowed per IP in the time window.Implementation (
src/app.js:72-74):Endpoint-Specific Limits
Authentication endpoints (src/routes/authRoutes.js:12-14):
- Window: 15 minutes
- Max requests: 5 per IP
- Applies to:
/api/auth/login,/api/auth/register
src/routes/chatRoutes.js:17-19):
- Window: 1 minute
- Max requests: 10 per user
- Applies to:
/api/chat/complete
Logging Configuration
Winston Logger Settings
Minimum log level to record.Log levels (highest to lowest priority):
error- Only errorswarn- Errors and warningsinfo- Standard operational info (recommended)http- HTTP requestsverbose- Detailed infodebug- Debug informationsilly- Everything
Directory path for log files. Created automatically if it doesn’t exist.Log rotation (
src/utils/logger.js):- Daily rotation via
winston-daily-rotate-file - Pattern:
application-%DATE%.log - Error logs:
error-%DATE%.log - Max file size: 20MB
- Max files: 14 days
- Development: Colorized console output, verbose errors
- Production: JSON format, sanitized error messages
Scheduled Tasks
Cron Jobs
Enable or disable scheduled background tasks.Implementation (Valid values:
server.js:106-108):true- Enable scheduled tasksfalse- Disable scheduled tasks
Scheduled tasks use
node-cron for:- Periodic data cleanup
- Analytics aggregation
- Notification processing
- Health checks
Complete .env Template
Here’s a complete template with all available options:Environment-Specific Configurations
Development
Production
Testing
Security Best Practices
Use Different Credentials Per Environment
Never use the same
JWT_SECRET or ANTHROPIC_API_KEY across development, staging, and production.Validation on Startup
The server validates critical configuration on startup:Next Steps
Quick Start
Start using CUIDO Backend
Authentication
Learn about the auth system
Deployment
Deploy to production
Architecture
Understand the system architecture
Troubleshooting
Server exits with 'ANTHROPIC_API_KEY not configured'
Server exits with 'ANTHROPIC_API_KEY not configured'
Ensure your And that the key starts with
.env file contains:sk-ant-.MongoDB connection fails
MongoDB connection fails
Check:
- MongoDB is running:
sudo systemctl status mongod MONGODB_URIis correct in.env- Network connectivity if using MongoDB Atlas
- Firewall rules allow connection to port 27017
JWT tokens not working
JWT tokens not working
Verify:
JWT_SECRETis set and not empty- Same secret used for signing and verification
- Token hasn’t expired (check
JWT_EXPIRES_IN)
CORS errors in browser
CORS errors in browser
Add your frontend URL to Restart the server after changing
ALLOWED_ORIGINS:.env.Rate limit blocking legitimate requests
Rate limit blocking legitimate requests
Increase limits for development:Or disable temporarily by commenting out the rate limiter in
src/app.js:96.