Skip to content

CLI

Terminal window
envvet [options]

Run with no arguments, envvet auto-detects .env and .env.example in the current directory, compares them, prints a report, and exits non-zero if anything has drifted.

Add envvet as a dev dependency:

Terminal window
npm install --save-dev envvet
# or: pnpm add -D envvet · yarn add -D envvet

Install it globally to run it anywhere:

Terminal window
npm install -g envvet

Or run it without installing:

Terminal window
npx envvet

From a project root containing .env and .env.example:

Terminal window
envvet
Terminal window
Missing (1)
• LOG_LEVEL
Empty (1)
• API_KEY
Extra (1)
• EXTRA_THING

On success:

Terminal window
All environment variables present.
FlagDefaultDescription
--env <path>.envPath to the env file to check.
--example <path>.env.examplePath to the contract file.
--allow-extrafalseDon’t fail on keys present in .env but not in the example.
--jsonfalseEmit machine-readable JSON instead of the report.
-h, --helpShow help.
-v, --versionShow the version.
CodeMeaning
0All environment variables present.
1Problems found (missing / empty, or extra when not allowed).
2Runtime error (e.g. the example file could not be read).

A missing .env is not a runtime error — every key is simply reported as missing, and the command exits 1. Only an unreadable example file (it’s the contract; without it there’s nothing to check against) produces exit code 2. An unknown flag also exits 2. These codes make envvet a drop-in CI step: a non-zero exit fails the job.

Check non-standard paths:

Terminal window
envvet --env config/.env.local --example config/.env.example

Allow extra keys in .env (only fail on missing or empty):

Terminal window
envvet --allow-extra

Machine-readable output for custom tooling:

Terminal window
envvet --json
{
"missing": ["LOG_LEVEL"],
"extra": ["EXTRA_THING"],
"empty": ["API_KEY"],
"ok": false
}

The JSON object is the same CompareResult returned by the library API, so the CLI and the library report drift identically. --json always exits with the normal exit code (0 / 1), so you can both branch on the output and rely on the status.

envvet ships a small library alongside the CLI, so you can wire env validation into your own scripts and tooling. See the API reference for parseEnv, compareEnv, and their types.