scl339-env-validator
v1.0.0
Published
Validate .env files against .env.example — detect missing keys, extra keys, and type mismatches. Works as both a CLI tool and a GitHub Action.
Maintainers
Readme
env-validator
🔍 Validate .env files against .env.example — catch missing keys, extra keys, and type mismatches before they cause production bugs.
🚀 Features
- ✅ Missing keys — Variables in
.env.examplebut not in.env - ⚠️ Extra keys — Variables in
.envbut not in.env.example - 🔤 Type inference — Detect string/boolean/integer/float/URL mismatches
- 🔧
--fixmode — Auto-add missing keys from.env.example - 🤖 GitHub Action — Use it in CI/CD pipelines
- 📦 Zero runtime deps — CLI mode uses only Node.js built-ins
- 📊 JSON output — Machine-readable for CI integration
📦 Install
# Install globally
npm i -g env-validator
# Or use directly
npx env-validator🎯 Usage
CLI
# Basic validation
env-validator
# Custom file paths
env-validator .env.production --example .env.example.prod
# With strict type checking
env-validator --strict-types
# JSON output (for CI)
env-validator --json
# Fix mode: add missing keys
env-validator --fixExit Codes
| Code | Meaning |
|------|---------|
| 0 | All valid |
| 1 | Missing keys or type mismatches |
GitHub Action
name: Validate Environment
on: [push]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate .env
uses: SCL339/env-validator@v1
with:
env-path: .env
example-path: .env.example
strict-types: 'true'📋 Example Output
✗ Missing keys (in .env.example but not in .env): 2
- DATABASE_URL
- REDIS_HOST
! Extra keys (in .env but not in .env.example): 1
- DEBUG_MODE=true
! Type mismatches: 1
- PORT: expected string, got integer🔧 Type Inference
| Value | Type |
|-------|------|
| true / false | boolean |
| 42 | integer |
| 3.14 | float |
| https://... | url |
| [email protected] | email |
| "hello" / hello | string |
📚 Related Projects
- SCL339/whatsnew-cli — See what's new in your GitHub repos
- SCL339/repo-stats-dashboard — Beautiful repo stats dashboards
- SCL339/json-to-types — JSON to TypeScript types converter
📄 License
MIT © SCL339
