@reactmode/env-check
v1.0.1
Published
Validate .env against .env.example
Readme
# @reactmode/env-check
Validate your `.env` file against `.env.example` before runtime. Catch missing or extra environment variables early — especially useful for Next.js, Vite, and Node.js projects.
## 📦 Installation
### Using npx (recommended)
```bash
npx @reactmode/env-check
```Install globally
npm install -g @reactmode/env-checkThen run:
env-check🚀 What It Does
Compares:
.env.env.example
And reports:
- ❌ Missing variables (defined in
.env.examplebut not in.env) - ⚠️ Extra variables (defined in
.envbut not in.env.example) - ✅ Valid environment when both match
The command exits with:
0→ No issues found1→ Mismatch detected
This makes it suitable for CI pipelines.
📁 Expected Project Structure
Your project should contain:
.env
.env.exampleExample
.env.example
VITE_API_URL=
VITE_CLIENT_URL=
VITE_LUMI_API_KEY=.env
VITE_API_URL=https://api.example.com
VITE_CLIENT_URL=http://localhost:5173
VITE_LUMI_API_KEY=abc123🧪 Example Output
✅ Valid Case
✅ Environment variables are valid❌ Missing Variables
Missing variables:
- VITE_API_URL⚠️ Extra Variables
Extra variables not in .env.example:
- VITE_UNUSED_VAR💡 Why Use This?
Environment issues are often discovered at runtime:
- Undefined API URLs
- Missing client URLs
- Incorrect deployment configuration
- Broken production builds
This tool shifts that validation to development time.
Useful for:
- Next.js projects
- Vite projects
- Node APIs
- CI/CD pipelines
- Team onboarding
🛠 How It Works
- Reads
.env.example - Reads
.env - Parses both using
dotenv - Compares key existence (not value truthiness)
- Reports structural mismatches
Empty values like:
API_KEY=are treated as valid if the key exists.
🔄 Exit Codes
| Exit Code | Meaning | | --------- | ----------------------------------- | | 0 | Environment files match | | 1 | Missing or extra variables detected |
Example CI usage:
env-check && echo "Environment valid"📌 Roadmap
Planned improvements:
--fixflag to auto-add missing keys- Custom file path support
- Strict mode
- Sorting suggestions
- Formatting validation
👤 Author
Built by ReactMode.
