Skip to content

abdullah43577/env-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# @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-check

Then run:

env-check

🚀 What It Does

Compares:

  • .env
  • .env.example

And reports:

  • ❌ Missing variables (defined in .env.example but not in .env)
  • ⚠️ Extra variables (defined in .env but not in .env.example)
  • ✅ Valid environment when both match

The command exits with:

  • 0 → No issues found
  • 1 → Mismatch detected

This makes it suitable for CI pipelines.

📁 Expected Project Structure

Your project should contain:

.env
.env.example

Example

.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:

  • --fix flag to auto-add missing keys
  • Custom file path support
  • Strict mode
  • Sorting suggestions
  • Formatting validation

👤 Author

Built by ReactMode.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors