A lightweight command-line tool for parsing, validating, and manipulating .env files with zero dependencies.
- Parse
.envfiles and output as JSON, YAML, or shell export format - Validate environment variable syntax and detect common issues
- Merge multiple
.envfiles with conflict detection - Extract specific variables by key or pattern
- Template support for variable substitution (
${VAR}syntax) - Diff two
.envfiles to see what changed - Sort variables alphabetically or by custom order
- Comment preservation when editing files
npm install -g envparse-cliOr use directly with npx:
npx envparse-cli parse .envenvparse parse .env
envparse parse .env --format json
envparse parse .env --format yamlenvparse validate .envenvparse merge .env .env.local .env.productionenvparse extract .env DATABASE_URL API_KEY
envparse extract .env --pattern "^AWS_"envparse diff .env.old .env.newenvparse sort .env --output .env.sortedenvparse template .env.template --vars .env.valuesInput .env:
# Database configuration
DATABASE_URL=postgresql://localhost:5432/mydb
DATABASE_POOL_SIZE=10
# API Keys
API_KEY=secret123
API_TIMEOUT=30
Parse to JSON:
$ envparse parse .env --format json
{
"DATABASE_URL": "postgresql://localhost:5432/mydb",
"DATABASE_POOL_SIZE": "10",
"API_KEY": "secret123",
"API_TIMEOUT": "30"
}Validate:
$ envparse validate .env
✓ .env is valid (4 variables, 2 comments)Extract pattern:
$ envparse extract .env --pattern "^DATABASE_"
DATABASE_URL=postgresql://localhost:5432/mydb
DATABASE_POOL_SIZE=10Can also be used as a Node.js library:
const{ parse, validate, merge }=require('envparse-cli');constenv=parse('.env');console.log(env.DATABASE_URL);constisValid=validate('.env');constmerged=merge(['.env','.env.local']);MIT
Pull requests welcome! Please ensure tests pass with npm test.