env-diff-cli
v1.0.2
Published
Compare .env files across environments - find missing variables before deployment
Downloads
259
Maintainers
Readme
env-diff-cli
Compare .env files across environments — catch missing variables before deployment.
Install
npm install -g env-diff-cliUsage
env-diff <file1> <file2> [options]
env-diff --check <template> <target>Commands
Basic diff
env-diff .env .env.productionShows missing, extra, and changed variables between the two files.
Missing only
env-diff .env .env.staging --missing-onlyOnly shows variables present in .env but absent in .env.staging.
Compare values
env-diff .env .env.production --valuesAlso compares values (secrets are masked as ***).
CI check mode
env-diff --check .env.example .envExits with code 1 if .env is missing any variables defined in .env.example. Perfect for CI/CD gates.
CI/CD Examples
Shell script
if env-diff --check .env.example .env; then
echo "All required env vars present — deploying"
else
echo "Missing env vars — aborting deploy"
exit 1
fiGitHub Actions
- name: Validate environment variables
run: env-diff --check .env.example .envGitLab CI
validate:
script:
- npx env-diff-cli --check .env.example .envDocker entrypoint
#!/bin/sh
env-diff --check /app/.env.example /app/.env || exit 1
exec "$@"Pre-deploy hook (package.json)
{
"scripts": {
"predeploy": "env-diff --check .env.example .env",
"deploy": "..."
}
}Output
| Symbol | Meaning |
|--------|---------|
| - KEY (red) | Missing in second file |
| + KEY (yellow) | Extra in second file (not in first) |
| ~ KEY (yellow) | Present in both but different value |
| ✓ KEY (green) | Present in both with same value |
Options
| Flag | Description |
|------|-------------|
| --missing-only | Only show vars in file1 missing from file2 |
| --values | Compare values (masked with ***) |
| --check | CI mode — exit 1 if target missing required vars |
| --no-color | Disable ANSI color output |
| -h, --help | Show help |
Exit Codes
| Code | Meaning |
|------|---------|
| 0 | No differences (or --check passed) |
| 1 | Differences found (or --check failed) |
| 2 | Error (file not found, bad arguments) |
.env Format Support
KEY=VALUEexport KEY=VALUE- Quoted values:
KEY="hello world",KEY='hello' - Inline comments:
KEY=value # this is ignored - Comment lines:
# full line comment - Empty lines ignored
License
MIT
