docs/ENV_SETUP.md
This project uses a hybrid approach for environment configuration:
.env files and converted to TypeScript constantssrc/environments/environment.ts - Development configurationsrc/environments/environment.prod.ts - Production configurationsrc/environments/environment.stage.ts - Staging configurationThese files contain base configuration like production, stage, and version flags.
.env - Environment variables for all environmentssrc/app/config/env.generated.ts - Auto-generated TypeScript constants (gitignored)The .env file contains secrets and environment-specific values that should not be committed to version control.
Create your .env file
cp .env.example .env
Add your environment variables
# .env
GOOGLE_DRIVE_TOKEN=your-token-here
DROPBOX_API_KEY=your-api-key-here
Access environment variables in your code
// Import from the generated constants (type-safe!)
import { ENV } from './app/config/env.generated';
// Direct access
const googleToken = ENV.GOOGLE_DRIVE_TOKEN;
// Or using utility functions (with type safety)
import { getEnv, getEnvOrDefault } from './app/util/env';
const googleToken = getEnv('GOOGLE_DRIVE_TOKEN');
const dropboxKey = getEnvOrDefault('DROPBOX_API_KEY', 'default-key');
The npm scripts automatically generate TypeScript constants from .env before running:
# Development
npm run startFrontend
# Production configuration
npm run startFrontend:prod
# Staging configuration
npm run startFrontend:stage
Note: All commands use the same .env file. The difference between environments is controlled by the Angular configuration (production/stage flags).
Build commands also generate constants before building:
# Production build
npm run buildFrontend:prod:es6
# Staging build
npm run buildFrontend:stage:es6
.env file and generates src/app/config/env.generated.tskeyof typeof ENV for autocomplete and type checking.env files to version controlenv.generated.ts is gitignored automatically.env.exampleAdd to .env:
NEW_API_KEY=your-api-key-here
The TypeScript types are automatically generated when you run any build/serve command
Use in your code with full type safety:
import { ENV } from './app/config/env.generated';
const apiKey = ENV.NEW_API_KEY;
// Or with utility function
import { getEnv } from './app/util/env';
const apiKey = getEnv('NEW_API_KEY'); // TypeScript knows all available keys!
.env and never in version control