Environment Variables Setup
This document describes how to set up and manage environment variables for local development.
Important: No Fallbacks
Never use fallback values for environment variables. If a required env var is missing, the app must fail loudly at startup. This prevents silent misconfiguration across environments (dev/prod).
typescript
// WRONG - never do this
const API_URL = import.meta.env.VITE_API_URL || 'https://some-default-url.com';
// CORRECT
if (!import.meta.env.VITE_API_URL) {
throw new Error('VITE_API_URL environment variable is required');
}
const API_URL = import.meta.env.VITE_API_URL;Required Variables
Web App (web/)
| Variable | Description |
|---|---|
VITE_FIREBASE_API_KEY | Firebase API key |
VITE_FIREBASE_AUTH_DOMAIN | Firebase auth domain |
VITE_FIREBASE_PROJECT_ID | Firebase project ID |
VITE_FIREBASE_STORAGE_BUCKET | Firebase storage bucket |
VITE_FIREBASE_MESSAGING_SENDER_ID | Firebase messaging sender ID |
VITE_FIREBASE_APP_ID | Firebase app ID |
VITE_FIREBASE_MEASUREMENT_ID | Firebase measurement ID |
VITE_FIREBASE_VAPID_KEY | Firebase VAPID key for push notifications |
VITE_API_URL | Cloud Run API URL (e.g., https://api-xwzj77tlfa-uc.a.run.app) |
Setting Environment Variables
- All variables are set in
.envat the project root. - Use
.env.localfor local overrides. - Never commit
.envfiles to version control.
Best Practices
- No fallbacks. Ever.
- No hardcoded environment-specific URLs in source code.
- Store secrets securely (never in the repo).
- Document any new variables in this file.
For information about deployment environments (dev/prod), see ENVIRONMENTS.md. For deployment instructions, see DEPLOYMENT.md.