Skip to main content

Environment Variables

All configuration is managed through environment variables in the .env file.

Required Variables

VariableDescriptionExample
DATABASE_URLPostgreSQL connection stringpostgresql://user:pass@localhost:5432/workforce?schema=public
NEXTAUTH_SECRETSession encryption key (32+ chars)a1b2c3d4... (use crypto.randomBytes)
NEXTAUTH_URLBase URL of the applicationhttps://workforce.example.com

Optional Variables

Server

VariableDefaultDescription
PORT3000HTTP port
NODE_ENVdevelopmentdevelopment, production, or test

Database

VariableDefaultDescription
DATABASE_URLPrimary database connection
DIRECT_URLDirect database connection (bypasses connection pooler)

Authentication

VariableDefaultDescription
NEXTAUTH_SECRETJWT/session secret
NEXTAUTH_URLCanonical URL

File Uploads

VariableDefaultDescription
UPLOAD_DIR./uploadDirectory for file uploads
MAX_FILE_SIZE10485760Maximum upload size in bytes (10 MB)

Email (Optional)

VariableDefaultDescription
SMTP_HOSTSMTP server hostname
SMTP_PORT587SMTP port
SMTP_USERSMTP username
SMTP_PASSSMTP password
SMTP_FROMSender email address

Environment-Specific Configuration

Development

NODE_ENV=development
DATABASE_URL="postgresql://workforce:dev_password@localhost:5432/workforce_dev?schema=public"
NEXTAUTH_SECRET="dev-secret-not-for-production"
NEXTAUTH_URL="http://localhost:3000"

Production

NODE_ENV=production
DATABASE_URL="postgresql://workforce:strong_password@db-host:5432/workforce?schema=public&sslmode=require"
NEXTAUTH_SECRET="your-64-char-cryptographically-random-string"
NEXTAUTH_URL="https://workforce.example.com"

Generating Secrets

# Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

# PowerShell
[System.Convert]::ToBase64String((1..32 | ForEach-Object { Get-Random -Maximum 256 }) -as [byte[]])

# OpenSSL
openssl rand -hex 32
caution

Never commit .env files to version control. The .gitignore file should include .env.