@elattariyassine/envcheck
v1.1.3
Published
A powerful Node.js CLI tool for validating, managing, and fixing environment variables
Maintainers
Readme
envcheck

A CLI tool that validates environment variables against
.env.exampleand helps fix any issues.
Features
- 🔍 Validate environment variables against
.env.example - 🛠️ Interactive mode to fix missing or invalid variables
- 📝 Support for different variable types (string, number, boolean)
- 🎨 Colorized output for better readability
- 🔒 Secure handling of sensitive information
- 🔄 Custom file paths for
.envand.env.example - 📊 Detailed validation reports
- 📋 Preserves file formatting and comments when updating files
Installation
You can use EnvCheck in two ways:
1. Using npx (Recommended for one-time use)
npx @elattariyassine/envcheck init
npx @elattariyassine/envcheck validate
npx @elattariyassine/envcheck fix2. Global Installation
npm install -g @elattariyassine/envcheckAfter global installation, you can use the commands directly:
envcheck init
envcheck validate
envcheck fixLocal Development Setup
To set up the project locally for development:
- Clone the repository:
git clone https://github.com/elattariyassine/envcheck.git
cd envcheck- Install dependencies:
npm install- Build the project:
npm run build- Link the package locally for testing:
npm linkNow you can use envcheck commands globally while developing.
Available Scripts
npm run build- Compiles TypeScript code to JavaScriptnpm test- Runs Jest testsnpm run lint- Runs ESLint to check code qualitynpm run format- Formats code using Prettier
Development Workflow
- Make your changes in the
srcdirectory - Run tests to ensure everything works:
npm test - Build the project:
npm run build - Test your changes using the CLI commands
To unlink the package when you're done:
npm unlinkUsage
Initialize Environment Files
npx @elattariyassine/envcheck initThis command will:
- Create a new
.env.examplefile with common environment variables - Include examples for different types of variables (string, number, boolean)
- Add helpful comments for each section
- Maintain proper formatting and structure
Validate Environment Variables
npx @elattariyassine/envcheck validateThis command will:
- Read your
.envand.env.examplefiles - Validate all required variables
- Check variable types and formats
- Display any errors or warnings
- Preserve all existing comments and formatting
Fix Environment Variables
npx @elattariyassine/envcheck fixThis command will:
- Check for missing or invalid variables
- Prompt you to enter values for missing variables (in interactive mode)
- Update your
.envfile with the new values - Maintain all existing comments, section headers, and formatting
- Keep the file structure clean and organized
Command Options
# Show version
npx @elattariyassine/envcheck -V
npx @elattariyassine/envcheck --version
# Fix command options
npx @elattariyassine/envcheck fix --file custom.env # Use custom .env file
npx @elattariyassine/envcheck fix --example custom.example # Use custom .env.example file
npx @elattariyassine/envcheck fix --no-interactive # Disable interactive mode
# Show help for any command
npx @elattariyassine/envcheck --help
npx @elattariyassine/envcheck validate --help
npx @elattariyassine/envcheck fix --helpExample Files
.env.example
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=myapp
DB_USER=postgres
DB_PASSWORD=your_password
# API Configuration
API_URL=https://api.example.com
API_KEY=your_api_key
API_TIMEOUT=5000
# Feature Flags
DEBUG_MODE=false
ENABLE_CACHE=true
# Email Configuration
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your_email
SMTP_PASS=your_password
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# Logging Configuration
LOG_LEVEL=info
LOG_FILE=app.log
# Security Configuration
JWT_SECRET=your_jwt_secret
SESSION_TIMEOUT=3600.env (with some invalid values)
# Database Configuration
DB_HOST=localhost
DB_PORT=not-a-number
DB_NAME=myapp
DB_USER=postgres
DB_PASSWORD=secret123
# API Configuration
API_URL=not-a-url
API_KEY=abc123
API_TIMEOUT=5000
# Feature Flags
DEBUG_MODE=not-a-boolean
ENABLE_CACHE=true
# Email Configuration
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your_email
SMTP_PASS=your_password
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# Logging Configuration
LOG_LEVEL=info
LOG_FILE=app.log
# Security Configuration
JWT_SECRET=your_jwt_secret
SESSION_TIMEOUT=3600Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
TODO
- [x] Create basic CLI structure
- [x] Implement environment variable validation
- [x] Add interactive mode for fixing variables
- [x] Add support for different variable types
- [x] Implement file formatting preservation
- [x] Add GitHub Actions workflows
- [x] Set up semantic-release
- [x] Add comprehensive tests
- [x] Add version command
- [x] Update license to ISC
- [x] Update package name to be scoped
- [ ] Add usage examples in README
License
ISC
