Overview
Environment variables configure the Money monorepo applications for different environments. Variables are stored in.env files locally and configured through your deployment platform in production.
Getting Started
Copy the example environment file:.env file with your actual values.
Variable Categories
Database
MongoDB connection configuration:MONGODB_URI
- Required: Yes (for secure and cashgap apps)
- Used by: Secure, CashGap
- Description: MongoDB connection string
- Example:
mongodb+srv://username:[email protected]/database?retryWrites=true&w=majority - Local dev:
mongodb://localhost:27017/money-dev - Production: Use MongoDB Atlas or managed instance
Authentication & Security
Secrets for JWT tokens and NextAuth:JWT_SECRET
- Required: Yes (for secure and cashgap apps)
- Used by: Secure, CashGap
- Description: Secret key for signing JWT access tokens
- Generation:
openssl rand -base64 32 - Example:
your-jwt-secret-key-here-make-it-long-and-random
JWT_REFRESH_SECRET
- Required: Yes (for secure app)
- Used by: Secure
- Description: Secret key for signing JWT refresh tokens
- Generation:
openssl rand -base64 32 - Example:
your-refresh-secret-key-here-make-it-different
AUTH_SECRET
- Required: Yes (for secure and cashgap apps)
- Used by: Secure, CashGap (NextAuth)
- Description: Secret for NextAuth.js session encryption
- Generation:
openssl rand -base64 32 - Example:
your-nextauth-secret-key-here-generate-with-openssl-rand-base64-32 - Aliases: May also be called
NEXTAUTH_SECRETin some contexts
OAuth Integration
Google Sign-In configuration:GOOGLE_CLIENT_ID
- Required: No (optional for Google OAuth)
- Used by: Secure, CashGap
- Description: Google OAuth 2.0 client ID
- Where to get: Google Cloud Console
- Example:
your-google-client-id-here.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET
- Required: No (optional, but required if using Google OAuth)
- Used by: Secure, CashGap
- Description: Google OAuth 2.0 client secret
- Where to get: Google Cloud Console
- Example:
GOCSPX-your-google-client-secret-here
Create OAuth credentials
Go to Google Cloud Console
Configure authorized redirect URIs
Add:
http://localhost:3000/api/auth/callback/google(development)https://your-domain.com/api/auth/callback/google(production)
Application URLs
Public-facing URLs and CORS configuration:NEXT_PUBLIC_APP_URL
- Required: Yes
- Used by: All apps
- Description: Public URL where the app is accessible
- Local dev:
http://localhost:3000 - Production:
https://your-domain.com - Note:
NEXT_PUBLIC_prefix makes it available in browser
ALLOWED_ORIGIN
- Required: Yes
- Used by: Secure (API CORS configuration)
- Description: Allowed origin for CORS requests
- Local dev:
http://localhost:3000 - Production:
https://your-domain.com - Multiple origins: Use comma-separated list (requires code changes)
Email Configuration
SMTP settings for sending emails:SMTP_HOST
- Required: No (optional for email features)
- Used by: Secure, CashGap
- Description: SMTP server hostname
- Example:
smtp.gmail.com - Default:
smtp.gmail.com
SMTP_PORT
- Required: No
- Used by: Secure, CashGap
- Description: SMTP server port
- Example:
587(STARTTLS) or465(SSL) - Default:
587
SMTP_SECURE
- Required: No
- Used by: Secure, CashGap
- Description: Use SSL/TLS for SMTP connection
- Values:
trueorfalse - Default:
false(uses STARTTLS on port 587)
SMTP_USER
- Required: No (required if SMTP enabled)
- Used by: Secure, CashGap
- Description: SMTP authentication username
- Example:
[email protected]
SMTP_PASSWORD
- Required: No (required if SMTP enabled)
- Used by: Secure, CashGap
- Description: SMTP authentication password
- Gmail: Use App Password, not your account password
- Example:
your-app-password-here
SMTP_FROM
- Required: No
- Used by: Secure, CashGap
- Description: “From” address for sent emails
- Example:
[email protected] - Default: Falls back to
SMTP_USERif not set
Environment Control
NODE_ENV
- Required: Auto-set by framework
- Used by: All apps
- Description: Node.js environment mode
- Values:
development,production,test - Set by: Next.js automatically
- Production: Set to
productionfor optimizations
Environment-Specific Configuration
Development (.env.local)
Production
Turbo.json Environment Variables
These variables are declared inturbo.json as dependencies for the build task:
Setting Variables by Platform
Vercel
- Go to Project Settings → Environment Variables
- Add each variable with its value
- Select environments: Production, Preview, Development
- Save changes
- Redeploy to apply
Docker
Pass via command line:Docker Compose
Security Best Practices
- Never commit secrets: Add
.envto.gitignore - Use strong secrets: Generate with
openssl rand -base64 32or longer - Rotate secrets regularly: Change secrets periodically
- Use different secrets per environment: Don’t reuse dev secrets in production
- Restrict access: Use secrets management tools (AWS Secrets Manager, Vault, etc.)
- Monitor usage: Track who accesses sensitive variables
- Use environment-specific credentials: Separate dev/staging/prod databases
Generating Secure Secrets
Troubleshooting
Variables Not Loading
- Check file name is exactly
.envor.env.local - Ensure file is in the app directory (e.g.,
apps/secure/.env) - Restart dev server after adding variables
- Check for typos in variable names
Build Fails with Missing Variables
- Check
turbo.jsonlists the variable - Ensure variable is set in build environment
- For
NEXT_PUBLIC_*variables, they must be set at build time
Database Connection Fails
- Verify
MONGODB_URIis correct - Check IP whitelist in MongoDB Atlas
- Ensure database user has correct permissions
- Test connection string with MongoDB Compass
OAuth Not Working
- Verify redirect URIs match exactly (including protocol and port)
- Check client ID and secret are correct
- Ensure OAuth consent screen is configured
- Check authorized domains include your domain
Next Steps
Database Setup
Configure MongoDB for production
Deployment Overview
Deploy your applications
Setup Guide
Initial development setup
Building
Build process details