env.ts — environment variables
Path: src/config/env.ts
When the server boots, it reads a .env file (like a sticky note with passwords).
env.ts turns those sticky notes into a typed, validated JavaScript object called env.
If a required secret is missing, the process throws and exits — better than running half-broken.
Helpers inside the file
| Function | Purpose |
|---|---|
require_(key) | Must exist or crash |
parsePositiveInt(key, fallback) | Number > 0 or use default |
parseBool(key, fallback) | 1/true/yes/on → true |
parseRateLimitStore() | 'mongo' | 'memory' (default 'memory') |
parseSampleRate(key, fallback) | Clamps to [0, 1] |
parseCsv(key) | Comma-separated, trimmed, no empties (used by OAUTH_REDIRECT_URIS) |
What env contains (groups)
Server: PORT
Database: MONGODB_URI
Auth: Google client id/secret, JWT secrets, refresh days, ALLOWED_ORIGIN, OAUTH_REDIRECT_URIS
Push: Firebase project id + service account JSON, NOTIFICATION_DRY_RUN, IST streak window hours
Rate limit: RATE_LIMIT_STORE, RATE_LIMIT_EVENT_SAMPLE_RATE
Workers: NOTIFICATION_WORKER_KEY
How other files should use it
import { env } from '../config/env.js'
// Good
const port = env.PORT
// Bad in routes/services
const port = process.env.PORTSee Env & secrets for a human table of variable names.
Last updated on