Overview
Envark’s validation feature ensures your.env files contain all the environment variables your code actually uses, with proper values. It catches configuration errors before deployment by comparing your .env files against real code usage.
Quick Start
How Validation Works
Validation follows a three-step process:1. Scan Codebase
Envark scans your project to discover all environment variables used in code:2. Parse .env File
Parse the target.env file to extract defined variables:
3. Compare & Validate
Cross-reference to identify issues:- Missing Variables: Used in code but not in .env
- Unused Variables: In .env but never used
- Empty Values: Variables with no value
- Placeholder Values: Variables with dummy values
Validation Statuses
Pass
Variable is properly configured:
- Present in .env file
- Has a real value
- Used in code
Warning
Non-critical issue:
- Defined but not used
- Missing but has default value
- Informational notices
Fail
Critical problem:
- Missing from .env
- Empty value
- Placeholder value
Validation Checks
Missing Variables
Variables used in code but not defined in the .env file:Unused Variables
Variables defined in .env but never referenced in code:Empty Values
Variables with no value assigned:Placeholder Values
Variables with obvious dummy values that need replacement:- Common
- TODO/FIXME
- Brackets
- Generic
Validation Output
CLI Output
TUI Output
JSON Output
Validation Result Structure
Use Cases
Pre-Deployment Validation
Multiple Environment Validation
CI/CD Integration
Docker Build Validation
CLI Options
Programmatic Usage
Best Practices
Validate Before Deploy
Always validate production .env files before deployment to catch configuration errors early.
Use .env.example
Maintain .env.example as a template and validate it in CI to ensure documentation is current.
Environment Parity
Validate all environment files (.env.development, .env.staging, .env.production) to ensure consistency.
Automate Checks
Add validation to CI/CD pipelines, pre-commit hooks, and deployment scripts.
Common Issues and Solutions
False positives for dynamic access
False positives for dynamic access
Issue: Envark reports variables as unused when accessed dynamically:Solution: Add a comment or explicitly reference variables:
Variables used in external tools
Variables used in external tools
Issue: Variables used by Docker, shell scripts, or external tools aren’t detected.Solution:
- Document external usage in comments
- Add to .env.example with explanatory notes
- Consider these as warnings rather than failures
Default values cause warnings
Default values cause warnings
Issue: Variables with defaults in code show as warnings when missing from .env.Solution: This is expected behavior. You can:
- Add them to .env explicitly for clarity
- Accept the warning as informational
- Use
--fail-on-warnings=falsein automation
Exit Codes
Related Features
- Risk Analysis - Analyze security risks in your environment variables
- Scanning - Discover all environment variables in your project
- AI Assistant - Get AI-powered recommendations for your configuration
Implementation Details
The validation engine is implemented in:src/tools/validate_env_file.ts: Main validation logic (lines 104-236)src/core/scanner.ts: Codebase scanningsrc/core/resolver.ts: Variable resolution
src/tools/validate_env_file.ts:104-236 for the complete validation implementation.