The @owll/node-env-checker package is a command-line tool used to check format errors, duplicate keys, empty values, and required environment variables in .env files. The output can be in either JSON or Markdown format.
- Reports invalid formats, empty values, and duplicate keys in
.envfiles. - Checks for missing required environment variables.
- Outputs reports in JSON or Markdown format.
You can install @owll/node-env-checker globally or as a project dependency.
To install globally, use the following command:
npm install -g @owll/node-env-checkerTo install as a project dependency:
npm install @owll/node-env-checker --save-devThen, you can run the @owll/node-env-checker command:
npx @owll/node-env-checkerBy default, @owll/node-env-checker checks the .env files in the current directory for invalid formats, empty values, and duplicate keys.
npx @owll/node-env-checkerIf you want to check for specific required environment variables (keys), you can use the --required flag. This flag takes a comma-separated list of keys. Example usage:
npx @owll/node-env-checker --required DB_HOST,DB_USER,DB_PASSThis command will check for the specified keys in your .env files and report any missing ones.
To get the report in JSON format, use the --report json flag:
npx @owll/node-env-checker --report jsonThe output might look like this:
[
{
"file": ".env",
"issues": [
{
"type": "INVALID_FORMAT",
"line": 3,
"content": "DB_HOST="
},
{
"type": "DUPLICATE_KEY",
"key": "DB_USER"
},
{
"type": "EMPTY_VALUE",
"key": "DB_PASS"
}
]
}
]To get the report in Markdown format, use the --report md flag:
npx @owll/node-env-checker --report mdThe output might look like this:
# Env File Report
## .env
✅ All variables are valid.
## .env.production
- ⚠️ **Invalid Format** (line 3): `DB_HOST=`
- ❌ **Repeat Key**: `DB_USER`
- ⚠️ **Empty Value**: `DB_PASS`@owll/node-env-checker reports the following error types:
- INVALID_FORMAT: Invalid format for a key-value pair (e.g.,
KEY=instead ofKEY=VALUE). - DUPLICATE_KEY: A key appears multiple times.
- EMPTY_VALUE: A key has an empty value.
- MISSING_REQUIRED: A required key is missing.
To view all available options:
npx @owll/node-env-checker --helpThis command will provide information about all available options and parameters.
For support, you can reach out via Buy Me A Coffee.
This project is licensed under the MIT License.