Env Config (TypeScript)
item / server / config
Typed loadEnv: one MissingEnvError naming every missing required var at once, blank counts as missing, and boolean capability flags so a feature degrades instead of crashing.
- type
- item
- files
- 2
- registry deps
- none
- npm deps
- none
installs
- ~/lib/automindz/env-config.ts
- ~/tests/env-config.test.mts
- env.A and env.flags.linear come back fully typed from the generics — no cast at the call site
- One MissingEnvError lists every missing required var at once, names only
- missingFor(flag) names exactly the unset vars for that capability, ready for a 503 body
Call const env = loadEnv({ required: ["DATABASE_URL"], optional: { PORT: "3000" }, flags: { linear: ["LINEAR_CLIENT_ID", ...] } }) once at startup, against process.env or an injected source in tests. env.DATABASE_URL is typed string and env.flags.linear is boolean with no cast at the call site; env.missingFor("linear") names the vars still unset, ready for a 503 body. A missing required var throws one MissingEnvError listing every missing name, sorted, names only — no value ever reaches the message. A blank string counts as missing. asInt and asBool coerce an optional value and throw with the var's name on a bad one. Does not parse .env files. Run the shipped test with node --test tests/env-config.test.mts.
Variations
one state per section
No previews for this item yet.
