Environment Variables
Complete reference for configuring the DesterLib API server via environment variables.
Required Variables
Section titled “Required Variables”DATABASE_URL
Section titled “DATABASE_URL”PostgreSQL connection string
DATABASE_URL=postgresql://username:password@host:port/database?schema=publicFormat: postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public
Examples:
# Docker Compose (default)DATABASE_URL=postgresql://desterlib:password@postgres:5432/desterlib?schema=public
# External databaseDATABASE_URL=postgresql://user:pass@db.example.com:5432/desterlib?schema=public
# Local developmentDATABASE_URL=postgresql://postgres:postgres@localhost:5433/desterlib_test?schema=publicUsed by: Prisma ORM for all database operations
Optional Variables
Section titled “Optional Variables”NODE_ENV
Section titled “NODE_ENV”Application environment mode
NODE_ENV=productionValues:
production- Production mode (default)development- Development mode with debug logging
Default: development
Effects:
- Logging verbosity
- Error message details
- CORS policy (more permissive in dev)
- Database query logging
API server port
PORT=3001Valid range: 1024-65535
Default: 3001 (from database settings)
Used by: Express HTTP server
RATE_LIMIT_WINDOW_MS
Section titled “RATE_LIMIT_WINDOW_MS”Rate limiting time window in milliseconds
RATE_LIMIT_WINDOW_MS=900000Default: 900000 (15 minutes)
Purpose: Prevents API abuse by limiting request frequency
Note: Localhost, scan routes, and stream routes are exempt from rate limiting.
RATE_LIMIT_MAX
Section titled “RATE_LIMIT_MAX”Maximum requests per window
RATE_LIMIT_MAX=100Default: 100 requests
Purpose: Maximum number of requests allowed per time window (see above)
Calculation: With defaults, clients can make 100 requests per 15 minutes.
Docker-Specific Variables
Section titled “Docker-Specific Variables”These are used by Docker Compose to configure the PostgreSQL container, not by the API directly:
POSTGRES_USER
Section titled “POSTGRES_USER”Database username
# In docker-compose.yml environment sectionPOSTGRES_USER: desterlibUsed by: PostgreSQL container initialization
POSTGRES_PASSWORD
Section titled “POSTGRES_PASSWORD”Database password
POSTGRES_PASSWORD: your_secure_passwordUsed by: PostgreSQL container initialization
POSTGRES_DB
Section titled “POSTGRES_DB”Database name
POSTGRES_DB: desterlibUsed by: PostgreSQL container initialization
Variables NOT Used
Section titled “Variables NOT Used”These variables are NOT read by the DesterLib API:
❌ FRONTEND_URL
Section titled “❌ FRONTEND_URL”Not used. CORS is configured automatically for local network access.
❌ JWT_SECRET
Section titled “❌ JWT_SECRET”Stored in database settings, not environment variables.
❌ TMDB_API_KEY
Section titled “❌ TMDB_API_KEY”Configured via Settings API in the application, not environment variables.
❌ POSTGRES_HOST / POSTGRES_PORT
Section titled “❌ POSTGRES_HOST / POSTGRES_PORT”The API only uses DATABASE_URL. Individual postgres connection vars are not read.
Configuration Methods
Section titled “Configuration Methods”Method 1: .env File (Recommended)
Section titled “Method 1: .env File (Recommended)”Create .env in the API directory:
CLI installation:
nano ~/.desterlib/.envGit installation:
nano apps/api/.envExample .env:
DATABASE_URL=postgresql://desterlib:password@postgres:5432/desterlib?schema=publicNODE_ENV=productionPORT=3001RATE_LIMIT_WINDOW_MS=900000RATE_LIMIT_MAX=100Method 2: Docker Compose Environment
Section titled “Method 2: Docker Compose Environment”Set directly in docker-compose.yml:
api: image: desterlib/api:latest environment: DATABASE_URL: postgresql://... NODE_ENV: production PORT: 3001 RATE_LIMIT_WINDOW_MS: 900000 RATE_LIMIT_MAX: 100Method 3: System Environment
Section titled “Method 3: System Environment”Export before running:
export DATABASE_URL="postgresql://..."export PORT=3001pnpm startExamples
Section titled “Examples”Development Setup
Section titled “Development Setup”DATABASE_URL=postgresql://postgres:postgres@localhost:5433/desterlib_test?schema=publicNODE_ENV=developmentPORT=3001RATE_LIMIT_WINDOW_MS=60000 # 1 minute for testingRATE_LIMIT_MAX=1000 # More lenient for developmentProduction Setup
Section titled “Production Setup”DATABASE_URL=postgresql://desterlib:STRONG_PASSWORD@postgres:5432/desterlib?schema=publicNODE_ENV=productionPORT=3001RATE_LIMIT_WINDOW_MS=900000 # 15 minutesRATE_LIMIT_MAX=100 # Standard rate limitingHigh-Traffic Setup
Section titled “High-Traffic Setup”DATABASE_URL=postgresql://...NODE_ENV=productionPORT=3001RATE_LIMIT_WINDOW_MS=600000 # 10 minutes (shorter window)RATE_LIMIT_MAX=200 # Allow more requestsValidation
Section titled “Validation”Check Current Configuration
Section titled “Check Current Configuration”Start the server and check logs:
docker compose up -ddocker compose logs api | head -20You should see:
🚀 Server running on port 3001🔧 Environment: production🗄️ Database: postgresql://desterlib:***@postgres:5432/desterlibTest Database Connection
Section titled “Test Database Connection”# Check if API can reach databasecurl http://localhost:3001/healthShould return {"status":"OK",...}
Troubleshooting
Section titled “Troubleshooting”Database Connection Failed
Section titled “Database Connection Failed”Error: Error: P1001: Can't reach database server
Fixes:
- Check
DATABASE_URLformat - Verify database is running:
docker ps | grep postgres - Test connection:
Terminal window docker exec -it desterlib-postgres psql -U desterlib -d desterlib
Port Already in Use
Section titled “Port Already in Use”Error: EADDRINUSE: address already in use :::3001
Fixes:
- Change
PORTto different number (e.g.,3002) - Or kill process using port 3001:
Terminal window lsof -ti:3001 | xargs kill -9
Rate Limiting Too Aggressive
Section titled “Rate Limiting Too Aggressive”If clients get rate limited often:
# Increase limitsRATE_LIMIT_WINDOW_MS=1800000 # 30 minutesRATE_LIMIT_MAX=200 # 200 requestsThen restart: docker compose restart api
Security Recommendations
Section titled “Security Recommendations”Production Checklist
Section titled “Production Checklist”- ✅ Use strong, random database passwords
- ✅ Don’t commit
.envto git (it’s in.gitignore) - ✅ Use
NODE_ENV=productionin production - ✅ Keep rate limits reasonable
- ✅ Monitor logs for suspicious activity
Database Security
Section titled “Database Security”Generate secure password:
openssl rand -base64 32Use this for POSTGRES_PASSWORD in your database connection.
Related Documentation
Section titled “Related Documentation”- Installation Guide - Initial setup
- API Overview - API server documentation
- CLI Tool - CLI documentation