Zero-dependency environment variable validator for Node.js.
Fail fast at startup, with typed values and every error listed at once.
Every process.env value is a string. That one fact causes the same production bugs again and again:
"false" is truthySet DEBUG=false and your debug code still runs, because a non-empty string is truthy in JavaScript. env-saaf parses real booleans.
"3000" + 1 = "30001"Ports and numbers arrive as strings, so arithmetic silently becomes concatenation. env-saaf returns typed numbers and validated ports (0–65535).
A forgotten variable does not fail at startup — it fails on the first request that needs it. env-saaf refuses to boot and lists all problems in one error.
One schema, one call. The result is a frozen object with correctly typed values.
const { validateEnv } = require('env-saaf'); const env = validateEnv({ PORT: { type: 'port', required: true }, DEBUG: { type: 'boolean', default: false }, API_URL: { type: 'url', required: true }, ADMIN_EMAIL: { type: 'email', required: true }, LOG_LEVEL: { type: 'string', choices: ['info', 'warn', 'error'], default: 'info' }, }); // env.PORT is a number · env.DEBUG is a real boolean // anything wrong? One EnvSaafError listing every problem.
Your code and your .env.example drift apart silently. The CLI catches it — made for CI.
npx env-saaf scan ./srcLists every env var your code actually uses — dot access, bracket access and destructuring.
npx env-saaf check .Diffs code usage against .env.example — and with --schema, validates the real values too (use --values for another environment file). Exit code 1 if anything used is undocumented — or add --fix and let check append the missing keys for you.
npx env-saaf example ./srcDrafts a fresh .env.example straight from a code scan.
npx env-saaf print . --schema ./env.schema.jsPrints the effective configuration — coerced values and defaults — with sensitive rules and secret-named keys masked; --reveal shows the real values.
npx env-saaf init .Scaffolds a starter env.schema.js and a matching .env.example, or infers the schema from an existing example with --from-example.
maskSecrets(process.env)Log your config safely — secrets print masked (sk***56), never in full.
Built in the open, one honest step at a time.
validateEnv with typed coercion — string, number, boolean, url, port — plus required, defaults and choices. All errors collected at once.
.env parsing, code scanning for process.env usage, used-vs-documented diff, and the env-saaf check / scan CLI with CI exit codes.
Secret masking, .env.example generation from schema and from code scans, TypeScript definitions, stable API.
Ten fixes and features: loadEnv, strict mode, boolean on/off + y/n, inline comments in .env files, scanCode let/var support — including the project's first outside contribution.
Email type and pattern option, CLI --json output, per-key transform, ${VAR} interpolation, multi-file loadEnv, int type with min/max, and README recipes.
json, uuid and hex types, minLength/maxLength and hex length options, trim: false, loadEnv return-type inference, safer .env.example generation for secret keys — with two more outside contributions.
ipv4, semver and base64 types, check now compares real .env keys, global --version, example --write, scan reports unused keys, and check exits 1 on every finding — with a new outside contributor.
duration and host types, date and file types, non-throwing mode, ${VAR:-default} interpolation, CLI --schema validation, and duplicate-key errors in .env files — with eight outside contributions.
bigint and ipv6 types, grouped nested schemas, the array type, requiredIf/aliases/conflictsWith options, loadEnvAsync, toJsonSchema export, init and print commands, check --fix, and real-secret detection in check — the biggest release yet, with many outside contributions.
jwt type for JSON Web Token shape validation, stricter schemas (non-array choices and length off hex rejected up front), layered loadEnv interpolation, scanCode alias destructuring, and masked non-string secrets.