I've been building small Node/TS apps for a while and got tired of the usual dotenv pitfalls: forgetting to set required vars, type mismatches (string vs number/port), or accidentally leaking secrets in logs/errors.
So I made dotenv-gad: a lightweight wrapper around dotenv that adds strong TypeScript inference, schema-based validation, and some practical extras.
Main things it does:
- Define a schema → get fully typed env object with inference - Built-in validators for url, email, port, json, arrays, objects, etc. - Custom rules: min/max, regex, enum, transform, validate fn - Group related vars automatically (e.g. DB_HOST, DB_PORT → db: { host, port }) - Compose schemas from different modules - Redacts sensitive values in error messages - Comes with a CLI for check/sync/generate-types/fix/init/docs
It's still early (v1.3), but I use it in my own projects and it's already saves me.
npm: https://www.npmjs.com/package/dotenv-gad
Would love to hear your thoughts, especially: - How do you currently handle env validation in TS projects? - What features are missing for your workflow? - Any rough edges / bugs you've spotted?
Thanks for looking!