Validate .env files against .env.example --- catch missing variables before runtime.
Every dev team has this problem: someone adds a new env var to .env.example but another developer's .env is missing it, leading to a cryptic runtime error. envcheck catches that instantly.
- Zero dependencies --- pure Node.js
- Works in any project that uses
.envfiles - CI/CD friendly with JSON output and non-zero exit codes
- Respects
NO_COLORfor accessibility
# Global
npm install -g envcheck-cli
# Per-project (recommended)
npm install --save-dev envcheck-cli# Compare .env against .env.example in current directory
envcheck
# Custom file paths
envcheck --env config/.env.local --example config/.env.example
# Strict mode: fail if .env has extra vars not in .env.example
envcheck --strict
# Fail if any variable has an empty value
envcheck --no-empty
# Combine flags
envcheck --strict --no-empty
# JSON output (for CI pipelines)
envcheck --format json
# CI mode: exit code 1 on any issue
envcheck --ci| Flag | Description | Default |
|---|---|---|
--env <path> |
Path to the .env file |
.env |
--example <path> |
Path to the .env.example file |
.env.example |
--strict |
Fail if .env has extra vars not in .env.example |
false |
--no-empty |
Fail if any variable has an empty value | false |
--format json |
Output results as JSON | text |
--ci |
Exit code 1 on any issue (extra vars, empty values) | false |
-h, --help |
Show help message | |
-v, --version |
Show version number |
| Code | Meaning |
|---|---|
0 |
All checks passed |
1 |
Issues found (missing, extra in strict mode, or empty vars) |
2 |
Configuration error (file not found, unknown flag) |
# .github/workflows/envcheck.yml
name: Environment Check
on: [push, pull_request]
jobs:
envcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npx envcheck-cli --strict --no-empty --ci# .gitlab-ci.yml
envcheck:
stage: validate
image: node:20-alpine
script:
- npx envcheck-cli --strict --no-empty --ci
rules:
- changes:
- .env.exampleAdd to your package.json:
{
"scripts": {
"prestart": "envcheck --strict --no-empty"
}
}Or with Husky:
# .husky/pre-commit
npx envcheck --strict --no-emptyWhen using --format json, envcheck outputs structured data for programmatic use:
{
"ok": false,
"missing": ["DATABASE_URL", "REDIS_URL"],
"extra": ["DEBUG_MODE"],
"empty": ["API_KEY"],
"summary": {
"missingCount": 2,
"extraCount": 1,
"emptyCount": 1
}
}- Parses both
.envand.env.examplefiles - Compares the variable names (keys) between the two files
- Reports missing variables (in
.env.examplebut not in.env) - Reports extra variables (in
.envbut not in.env.example) - Optionally checks for empty values (
--no-empty) - Ignores comments (
#) and blank lines - Handles quoted values (
"value"and'value')
MIT --- Tate Lyman
If you find this useful, consider supporting the project:
SOL Wallet: NaTTUfDDQ8U1RBqb9q5rz6vJ22cWrrT5UAsXuxnb2Wr
- DevTools.run — Free developer tools
- @solscanitbot — Solana trading bot on Telegram
- GitHub Sponsors