dotenv-keys-diff
v1.0.0
Published
Compare .env and .env.example keys — find missing and extra variables.
Maintainers
Readme
dotenv-keys-diff
Compare .env and .env.example keys. Find variables missing from your local env or present in env but undocumented in the example file.
npm package name:
dotenv-keys-diff(dotenv-diffwas already taken). Thedotenv-diffbinary is also installed as an alias.
Install
npm install -g dotenv-keys-diff
# or one-shot:
npx dotenv-keys-diffCLI
dotenv-keys-diff
dotenv-keys-diff --env .env.local --example .env.example
dotenv-keys-diff --check-empty
dotenv-keys-diff --json| Option | Description |
|--------|-------------|
| --env <path> | Env file (default: .env) |
| --example <path> | Example file (default: .env.example) |
| --cwd <path> | Working directory |
| --check-empty | Fail when env values are empty |
| --allow-missing | Treat a missing .env as empty |
| --json | Machine-readable output |
| -q, --quiet | Suppress success message |
| -h, --help | Help |
| -v, --version | Version |
Exit codes: 0 match · 1 differences · 2 usage/file error
Example output
Missing in env (1) — present in example, absent in env:
- DATABASE_URL
Extra in env (1) — present in env, absent in example:
+ DEBUG_SECRETAPI
import { parseEnv, diffEnv, diffFiles } from "dotenv-keys-diff";
const env = parseEnv("FOO=1\nBAR=2\n");
const example = parseEnv("FOO=\nBAZ=\n");
const result = diffEnv(env, example);
// { missing: ["BAZ"], extra: ["BAR"], empty: [], ok: false }
const fromDisk = diffFiles({
cwd: process.cwd(),
env: ".env",
example: ".env.example",
checkEmpty: false,
});CI
Fail the build when someone adds an env var without updating .env.example:
- run: npx dotenv-keys-diff --env .env.ci --example .env.exampleOr keep example as the source of truth when CI has no .env:
npx dotenv-keys-diff --allow-missingLicense
MIT
