A fast and flexible CLI tool to validate your
.envfiles against a JSON or YAML schema.
Tame your environment configs. Catch missing or invalid .env variables before they break your app.
- ✅ Schema validation for
.envfiles (JSON and YAML) - ♺ JSON/YAML schema generation from an existing
.envfile - 🔢 Type checking for
string,number, andboolean ⚠️ Support for optional keys and default values- 🎟️ Support for allowed values (enums), patterns (RegEx), min/max, minLength/maxLength, length
- 🟡 Support for warning suppression - keeping output clean in CI
- ❕ Optional fail-fast mode - stop on first error
- 🎨 Color-coded terminal output for easy debugging
- ⚙️ Works great in development and CI/CD pipelines
go install github.com/chidinma21/env-lint@latestThis will download, build, and place the env-lint binary in your $GOPATH/bin (or $GOBIN).
Make sure that directory is in your PATH so you can run env-lint from anywhere.
git clone https://github.com/chidinma21/env-lint.git
cd env-lint
go build -o env-lintYou’ll need:
-
A
.envfile with your environment variables -
A
schema.jsonorschema.yamlfile describing expected keys, types, and whether they’re required
| Rule | Type | Description |
|---|---|---|
type |
string | The variable type: string, number, or boolean. (required) |
required |
bool | If true, the key must exist in .env. |
default |
any | Value to use if key is missing. |
allowed |
[]any | List of valid values (enum). |
pattern |
string (RegEx) | Value must match this regex pattern. |
length |
int | Exact length of the string. |
minLength |
int | Minimum string length. |
maxLength |
int | Maximum string length. |
min |
float | Minimum numeric value. |
max |
float | Maximum numeric value. |
customError |
string | Custom error message when validation fails. |
PORT=3000
APP_NAME=env-lint
DEBUG_MODE=true
MAX_USERS=50
API_KEY=abc123{
"PORT": {
"type": "number",
"required": true,
"min": 1000,
"max": 9999
},
"DEBUG_MODE": {
"type": "boolean",
"required": false,
"default": false
},
"APP_NAME": {
"type": "string",
"required": true,
"minLength": 3,
"maxLength": 20
},
"MAX_USERS": {
"type": "number",
"required": false,
"default": 10,
"min": 1,
"max": 100
},
"API_KEY": {
"type": "string",
"required": true,
"pattern": "^[a-zA-Z0-9]+$",
"length": 6,
"customError": "API_KEY must be alphanumeric and exactly 6 characters long"
},
"ENV": {
"type": "string",
"allowed": ["development", "staging", "production"],
"default": "development"
}
}./env-lint validate --env .env --schema schema.jsonOr using shorthand flags:
./env-lint validate -e .env -s schema.json🚀 .env file loaded successfully
🚀 Schema file loaded successfully
🔍 Validating environment variables...
❌ APP_NAME Too short (minLength = 3)
❌ API_KEY API_KEY must be alphanumeric and exactly 6 characters long
❌ ENV Invalid value: "local" (allowed: development, staging, production)
🟡 DEBUG_MODE Optional key missing (ok)
🟡 MAX_USERS Using default value: 10
━━━━━━━━━━━━━━━━━━━━━━━
❌ Validation failed. Please fix the errors above.🚀 .env file loaded successfully
🚀 Schema file loaded successfully
🔍 Validating environment variables...
━━━━━━━━━━━━━━━━━━━━━━━
✅ All checks passed. Your .env config looks great!./env-lint validate [flags]-
-e, --envstring: Path to the.envfile (default:.env) -
-s, --schemastring: Path to the schema file (default: schema.json) -
-w, --suppress-warningsboolean: Suppress non-critical warnings in output -
-t, --strict-modeboolean: Fail if.envcontains keys not defined in schema -
-f, --fail-fastboolean: Stop validation after the first error
./env-lint generate-schema [flags]-
-e, --envstring: Path to the.envfile to generate schema from (default:.env) -
-f, --formatstring: Output format:json,yaml, oryml(default:json)
Contributions, issues, and feature requests are welcome! Please:
-
Fork the repository
-
Create a branch: git checkout -b feature/your-feature
-
Make your changes and add tests
-
Commit: git commit -m "Add some feature"
-
Push: git push origin feature/your-feature
-
Open a Pull Request
-
Ensure code follows Go formatting (gofmt) and include tests where applicable.
MIT © 2025 Chidinma Onuora
Made with ❤️ in Go.