env-saaf checks your environment variables the moment your app starts — typed values, defaults, choices — and reports every problem at once, in plain language. No more silent config bugs at 2 a.m.
Every value in process.env is a string, and nothing checks them for you. These bugs ship quietly and explode loudly.
"false" is truthyYou set DEBUG=false — and the app still runs in debug mode, because the string "false" is truthy in JavaScript.
"3000" + 1 = "30001"PORT arrives as a string. The first time your code does arithmetic on an env value, it silently concatenates instead.
A variable exists on your laptop but never made it to the server. The app crashes on boot — or worse, runs with undefined.
The file says DATABSE_URL. Your code reads DATABASE_URL, gets nothing, and nobody is ever told.
One small schema at startup replaces scattered process.env reads — and when something is wrong, you hear about all of it at once.
const { validate } = require('env-saaf'); const env = validate({ PORT: { type: 'port', required: true }, DEBUG: { type: 'boolean', default: false }, API_KEY: { type: 'string', required: true }, MODE: { type: 'string', choices: ['development', 'production'], default: 'development' }, }); // env.PORT is a number. env.DEBUG is a real boolean. app.listen(env.PORT);
✗ EnvSaafError: 2 problems with your environment • PORT — expected a port (0–65535), got "abc" • API_KEY — missing (required) Every problem is listed in one error — fix them all in a single pass, instead of crashing, fixing one, and crashing again. Secret values are masked in the output, so the error is safe to log and share.
Small surface, sharp edges. env-saaf does one job — trustworthy configuration — and does it completely.
Strings become real numbers, booleans and ports. "false" becomes false; "3000" becomes 3000.
One EnvSaafError lists every missing, invalid and unexpected variable — no fix-one-crash-again loop.
Read your .env file and validate it in a single call, with defaults applied and types converted.
Fail on variables that exist but are not in your schema, so a typo'd name can never hide in the file.
check diffs your real file against the example; scan finds every process.env read in your code. Add --fix and check appends the missing keys itself.
Values are masked in error messages and output — safe for logs, CI and screenshots.
The result type is inferred from your schema: env.PORT is a number, not a string, in your editor too.
Nothing extra lands in your node_modules. Installs in a blink and audits clean, every time.
This little demo runs the same rules as the real package. Break something — a bad port, a missing key — and validate.
Clear API_KEY or type a bad PORT, then validate again — every problem shows up at once, just like the real thing.
Most config bugs are really .env.example drift. The CLI keeps the example, the real file and your code in agreement.
npx env-saaf check
Compare your .env against .env.example and fail CI when they drift apart.
npx env-saaf scan
Scan your codebase for process.env reads and check that each one is declared.
npx env-saaf check --json
Machine-readable output for scripts and CI dashboards. Shipped in v1.2.0.
env-saaf grows in public — and contributors are already shaping it. Thank you.
Really. env-saaf has no runtime dependencies at all: what you install is the package itself, nothing else. That means faster installs, a smaller audit surface, and nothing transitive to break later.
dotenv loads a file into process.env; env-saaf makes sure what is there is actually valid — typed, present and allowed. Use env-saaf's loadEnv to do both in one call, or keep dotenv and validate process.env right after it loads.
Your app stops at startup with one EnvSaafError listing every problem — missing, invalid and unexpected variables together. Failing loudly at boot beats failing quietly in production.
Yes. env-saaf ships its own type definitions, and the validated result is inferred from your schema — env.PORT is typed as a number, not a string.
Node.js 16 and newer.