Skip to content

Environment Variables

Complete reference for configuring the DesterLib API server via environment variables.

PostgreSQL connection string

DATABASE_URL=postgresql://username:password@host:port/database?schema=public

Format: postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public

Examples:

# Docker Compose (default)
DATABASE_URL=postgresql://desterlib:password@postgres:5432/desterlib?schema=public
# External database
DATABASE_URL=postgresql://user:pass@db.example.com:5432/desterlib?schema=public
# Local development
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/desterlib_test?schema=public

Used by: Prisma ORM for all database operations

Application environment mode

NODE_ENV=production

Values:

  • 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=3001

Valid range: 1024-65535
Default: 3001 (from database settings)

Used by: Express HTTP server

Rate limiting time window in milliseconds

RATE_LIMIT_WINDOW_MS=900000

Default: 900000 (15 minutes)

Purpose: Prevents API abuse by limiting request frequency

Note: Localhost, scan routes, and stream routes are exempt from rate limiting.

Maximum requests per window

RATE_LIMIT_MAX=100

Default: 100 requests

Purpose: Maximum number of requests allowed per time window (see above)

Calculation: With defaults, clients can make 100 requests per 15 minutes.

These are used by Docker Compose to configure the PostgreSQL container, not by the API directly:

Database username

# In docker-compose.yml environment section
POSTGRES_USER: desterlib

Used by: PostgreSQL container initialization

Database password

POSTGRES_PASSWORD: your_secure_password

Used by: PostgreSQL container initialization

Database name

POSTGRES_DB: desterlib

Used by: PostgreSQL container initialization

These variables are NOT read by the DesterLib API:

Not used. CORS is configured automatically for local network access.

Stored in database settings, not environment variables.

Configured via Settings API in the application, not environment variables.

The API only uses DATABASE_URL. Individual postgres connection vars are not read.

Create .env in the API directory:

CLI installation:

Terminal window
nano ~/.desterlib/.env

Git installation:

Terminal window
nano apps/api/.env

Example .env:

DATABASE_URL=postgresql://desterlib:password@postgres:5432/desterlib?schema=public
NODE_ENV=production
PORT=3001
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100

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: 100

Export before running:

Terminal window
export DATABASE_URL="postgresql://..."
export PORT=3001
pnpm start
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/desterlib_test?schema=public
NODE_ENV=development
PORT=3001
RATE_LIMIT_WINDOW_MS=60000 # 1 minute for testing
RATE_LIMIT_MAX=1000 # More lenient for development
DATABASE_URL=postgresql://desterlib:STRONG_PASSWORD@postgres:5432/desterlib?schema=public
NODE_ENV=production
PORT=3001
RATE_LIMIT_WINDOW_MS=900000 # 15 minutes
RATE_LIMIT_MAX=100 # Standard rate limiting
DATABASE_URL=postgresql://...
NODE_ENV=production
PORT=3001
RATE_LIMIT_WINDOW_MS=600000 # 10 minutes (shorter window)
RATE_LIMIT_MAX=200 # Allow more requests

Start the server and check logs:

Terminal window
docker compose up -d
docker compose logs api | head -20

You should see:

🚀 Server running on port 3001
🔧 Environment: production
🗄️ Database: postgresql://desterlib:***@postgres:5432/desterlib
Terminal window
# Check if API can reach database
curl http://localhost:3001/health

Should return {"status":"OK",...}

Error: Error: P1001: Can't reach database server

Fixes:

  1. Check DATABASE_URL format
  2. Verify database is running: docker ps | grep postgres
  3. Test connection:
    Terminal window
    docker exec -it desterlib-postgres psql -U desterlib -d desterlib

Error: EADDRINUSE: address already in use :::3001

Fixes:

  1. Change PORT to different number (e.g., 3002)
  2. Or kill process using port 3001:
    Terminal window
    lsof -ti:3001 | xargs kill -9

If clients get rate limited often:

# Increase limits
RATE_LIMIT_WINDOW_MS=1800000 # 30 minutes
RATE_LIMIT_MAX=200 # 200 requests

Then restart: docker compose restart api

  • ✅ Use strong, random database passwords
  • ✅ Don’t commit .env to git (it’s in .gitignore)
  • ✅ Use NODE_ENV=production in production
  • ✅ Keep rate limits reasonable
  • ✅ Monitor logs for suspicious activity

Generate secure password:

Terminal window
openssl rand -base64 32

Use this for POSTGRES_PASSWORD in your database connection.