Package Exports
- env-sentinel
Readme
env-sentinel
π Intro
env-sentinel is a lightweight, zero-dependency CLI tool for analyzing .env files in Node.js projects β offering both schema-based validation and powerful linting to ensure your environment variables are correct, consistent, and production-safe.
In addition to verifying variable types and required keys, env-sentinel can detect subtle and hard-to-spot issues such as malformed keys, unsafe characters, unescaped shell tokens, duplicate references, invalid syntax, and YAML pitfalls β problems that typical schema validation canβt catch.
With fast execution and a human-readable schema format, env-sentinel eliminates the guesswork of .env.example files and bloated config validators β giving you clear, actionable feedback without writing custom validation logic.
β¨ Key Features
- β Lint .env files to catch formatting issues, unsafe syntax, and common misconfigurations
- β Validate environment variables against a defined schema
- β Simple schema format (e.g. VAR_NAME=required|number)
- β Smart type detection when generating from .env
- β Auto-generate schema with type inference from existing .env files with inferred
- β Zero dependencies and extremely fast
- β Ideal for local development, CI/CD, and team workflows
- β Fast fail with clear, colorized output
π¦ Installation
The easiest way to run env-sentinel is with npx (no installation required):
npx env-sentinel lint --file .envAlternatively, you can install it globally or as a local project dependency:
Using npm
# Global
npm install -g env-sentinel
# Local (in your project)
npm install --save-dev env-sentinelUsing yarn
# Global
yarn global add env-sentinel
# Local
yarn add --dev env-sentinelUsing pnpm
# Global
pnpm add -g env-sentinel
# Local
pnpm add -D env-sentinelThen run it:
npx env-sentinel lint --file .env # or just: env-sentinel lintInitialize schema file (.env-sentinel) from existing .env
npx env-sentinel init- Auto-detects types like number, boolean
- Creates .env-sentinel in current directory
Re-generate (overwrite existing)
npx env-sentinel init --forceUse custom .env to generate schema
npx env-sentinel init --env-file .env.localSchema Format (.env-sentinel)
Each line represents a variable and its rule:
DB_HOST=required
DB_PORT=required|number
DEBUG=optional|boolean
NODE_ENV=optional|enum:development,production,testSupported Rules
| Syntax | Description |
|---|---|
| required | Must be defined |
| optional | Can be missed |
| number | Must be a number |
| string | Can be anything |
| boolean | Must be true of false |
| min:value | Is greater than or equal to the specified minimum value; for strings, it checks the length, and for numbers, it checks the numerical value. |
| max:value | Is less than or equal to the specified maximum value; for strings, it checks the length, and for numbers, it checks the numerical value. |
| enum:foo,bar | Must match one of listed values |
Usage
Check .env file
npx env-sentinelDefaults:
- .env (env file)
- .env-sentinel (schema file)
Validate or Lint custom files
# Validate .env against a schema
npx env-sentinel validate --env-file .env.production --schema config/prod.schema
# Lint .env for formatting issues
npx env-sentinel lint --file .env.productionSample Output
On success:
β Environment validation passed!
On failure:
> π΅ .env:101 [notice] no-empty-value β Variable "COMMENTED_OUT" has an empty value
> π‘ .env:102 [warning] no-unquoted-multiline-value β Unquoted multiline-looking value in "MULTILINE"
> π .env:104 [error] no-invalid-key-delimiter β Variable name contains invalid delimiter: ":"
> π Missing required variable: DB_HOST
> π‘ Insecure value detected: DB_PASS=1234Why use env-sentinel?
- No runtime bloat β stays lightweight and fast
- More transparent than Joi/Zod configs
- Quick to set up and CI-friendly
- Fits modern DX (type-safe, CLI-ready, focused)
Roadmap (Coming Soon)
- Custom rule plugins
- GitHub Action integration
- VSCode extension
- .env.template generator from schema
- Dry run & suggestion mode
License
MIT license β Free to use, modify, and contribute!