Overview
The backend requires several environment variables for configuration. Copy.env.example to .env and configure the following variables.
Required Variables
All of these variables are required for the application to start. The server validates them on startup.Server Configuration
Port number where the server will listen for requests.
Application environment. Affects error handling, logging, and CORS.Options:
development, production, testURL of your frontend application. Used for CORS configuration.
Database Configuration
PostgreSQL connection string. This is the primary database connection.Format:
postgresql://[user]:[password]@[host]:[port]/[database]Authentication (Clerk)
Secret key from your Clerk dashboard. Used for server-side authentication.Format:
sk_test_... (test) or sk_live_... (production)Get this from Clerk Dashboard → Your App → API Keys → Secret Keys
Publishable key from your Clerk dashboard. Safe to expose in frontend code.Format:
pk_test_... (test) or pk_live_... (production)Storage (Supabase)
Your Supabase project URL. Used for file storage operations.Format:
https://[project-id].supabase.coGet this from Supabase Dashboard → Your Project → Settings → API
Supabase anonymous/public API key. Used for authenticated storage access.
Docker-Specific Variables
These variables are only used in the Docker Compose setup for local development:PostgreSQL username for Docker container.
PostgreSQL password for Docker container.
PostgreSQL database name for Docker container.
Environment Variable Validation
The application validates all required environment variables on startup using thevalidateEnv() function in src/config/env.config.ts:
Example Configurations
Development (.env)
Production (.env)
Platform-Specific Setup
Render
- Go to your service → Environment
- Add each environment variable as a key-value pair
- Render automatically provides
DATABASE_URLif you attach a PostgreSQL database
Railway
- Go to your project → Variables
- Add each variable individually or use “Raw Editor” for bulk import
- Railway auto-generates
DATABASE_URLwhen you add a PostgreSQL plugin
Vercel (for serverless functions)
- Go to your project → Settings → Environment Variables
- Add variables for each environment (Production, Preview, Development)
- Use Vercel Postgres integration for
DATABASE_URL
Docker Compose
Docker Compose automatically reads from your.env file. You can also set variables directly in docker-compose.yml:
Security Best Practices
Use different keys for development and production
Use different keys for development and production
Use Clerk’s test keys (
sk_test_..., pk_test_...) for development and live keys (sk_live_..., pk_live_...) for production.Rotate credentials regularly
Rotate credentials regularly
Change your database passwords and API keys periodically, especially if they may have been exposed.
Use secrets management in production
Use secrets management in production
Platforms like Render, Railway, and Vercel provide built-in secrets management. Use these instead of committing credentials.
Limit CORS to your frontend only
Limit CORS to your frontend only
Set
FRONTEND_URL to your exact frontend URL, not a wildcard (*).Troubleshooting
”Missing required environment variables”
Make sure all required variables are set in your.env file:
“PORT must be a valid number”
EnsurePORT is a number without quotes:
Variables not being loaded
Make sure you’re using the correct.env file location:
.env:
Next Steps
Docker Deployment
Set up Docker for local development
Production Deployment
Deploy to production platforms
