Skip to content

A zero-config, framework-agnostic NPM package that validates and documents your environment variables from your .env.example file, preventing runtime errors before they happen.

Notifications You must be signed in to change notification settings

ArshTiwari2004/envguard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EnvGuard Logo

A zero-config, framework-agnostic NPM package and UI for validating and documenting your environment variables, straight from your .env.example file.

NPM Version Downloads GitHub Stars License CI Status


Quick Start

Install via NPM

npm install @arshtiwari/envguard

Add to Project Startup

require('envguard'); // Validates env vars on startup

Or Use CLI

npx envguard validate

Features

  • Zero-config - Works with existing .env.example
  • Framework-agnostic - Node.js, Next.js, React, Vue, etc.
  • Auto-documentation - Keep .env.example always updated
  • Interactive UI - Visual debugger for environment variables
  • Validation - Catch missing/invalid vars before runtime
  • Multiple Integration Methods - CLI, programmatic, and React UI

🧰 Tech Stack

Tech Stack

--

Category Technologies
Backend/Core TypeScript, Node.js
Schema Validation Zod, Custom Schema Generator
File Parsing dotenv, fs-extra
CLI yargs, commander
Frontend (UI) React.js, Vite , TailwindCSS
Testing Jest
CI/CD GitHub Actions

Installation and setup

1. Install

npm install --save-dev @arshtiwari/envguard
# or
yarn add -D @arshtiwari/envguard
# or
pnpm add -D @arshtiwari/envguard

2. Validate in CLI

npx envguard validate

3. Use Programmatically

const { runEnvguard } = require('envguard');
if (!runEnvguard()) {
process.exit(1);
}

4. Access frontend

cd ui
npm install
npm run dev

Visit http://localhost:5173 to view the UI.


Folder Structure

envguard/
β”œβ”€β”€ .env.example                # Example env file for validation
β”œβ”€β”€ .gitignore
β”œβ”€β”€ README.md                   # Project documentation
β”œβ”€β”€ package.json
β”œβ”€β”€ babel.config.js             # Babel config for transpiling (if needed)
β”œβ”€β”€ jest.config.js              # Jest config for tests
β”œβ”€β”€ tsconfig.json               # TypeScript config (optional)
β”œβ”€β”€ LICENSE
β”œβ”€β”€ dist/                       # Transpiled output for npm (ignored in VCS)
β”‚   └── ...                     # Compiled JS files
β”œβ”€β”€ src/                        # Main source code
β”‚   β”œβ”€β”€ index.js                # Main entry point (exports runEnvguard)
β”‚   β”œβ”€β”€ parser/
β”‚   β”‚   └── envExampleParser.js
β”‚   β”œβ”€β”€ schema/
β”‚   β”‚   └── schemaGenerator.js
β”‚   β”œβ”€β”€ validator/
β”‚   β”‚   └── validator.js
β”‚   β”œβ”€β”€ reporter/
β”‚   β”‚   └── errorReporter.js
β”‚   β”œβ”€β”€ cli/
β”‚   β”‚   └── cli.js              # CLI entry point
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   └── helpers.js
β”‚   └── types/
β”‚       └── index.d.ts          # Type definitions
β”œβ”€β”€ server/                     # Backend server for live UI (optional)
β”‚   └── server.js
β”œβ”€β”€ scripts/                    # Utility scripts (e.g., generate .env.example)
β”‚   └── generateEnvExample.js
β”œβ”€β”€ tests/                      # Jest test files
β”‚   β”œβ”€β”€ parser.test.js
β”‚   β”œβ”€β”€ schema.test.js
β”‚   β”œβ”€β”€ validator.test.js
β”‚   └── cli.test.js
β”œβ”€β”€ ui/                         # React UI dashboard (dev/optional)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ main.jsx
β”‚   β”‚   β”œβ”€β”€ index.css
β”‚   β”‚   └── components/
β”‚   β”‚       └── EnvTable.jsx
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   β”œβ”€β”€ index.html
β”‚   β”‚   └── env-vars.json       # (for demo, replaced by API in prod)
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── vite.config.js
β”œβ”€β”€ website/                    # Landing page (for npm promotion)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ main.jsx
β”‚   β”‚   └── components/
β”‚   β”‚       β”œβ”€β”€ Hero.jsx
β”‚   β”‚       └── Pricing.jsx
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── index.html
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── vite.config.js

How It Works

  1. Parse your .env.example for variable names and defaults.
  2. Generate a validation schema automatically.
  3. Validate your actual environment (process.env) against the schema.
  4. Report errors in CLI, programmatically, or visually in the UI.

File Structure Example

project-root/
β”œβ”€β”€ .env                # Local environment (gitignored)
β”œβ”€β”€ .env.example        # Template with all required vars
β”œβ”€β”€ .env.development    # Environment-specific vars
β”œβ”€β”€ .env.production
└── package.json

Your .env.example should look like:

# Required variables
API_KEY=your_api_key_here
DATABASE_URL=postgres://user:pass@localhost:5432/db

# Optional variables
# PORT=3000
# DEBUG=false

Advanced Configuration

Create envguard.config.js for custom rules:

module.exports = {
  // Custom schema rules
  rules: {
    API_KEY: {
      minLength: 32,
      pattern: /^sk_[a-zA-Z0-9]+$/
    }
  },
  
  // Additional environments
  environments: ['staging', 'test'],
  
  // Custom error messages
  messages: {
    missing: '🚨 Missing required env var: {var}',
    invalid: '❌ Invalid value for {var}: {error}'
  }
};

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.


License

MIT Β© Arsh Tiwari


πŸ“¬ Contact

Have questions or need help? Feel free to reach out!

For bug reports or feature requests, please open an issue on GitHub.


Happy coding! May your environment variables always be valid. ✨

About

A zero-config, framework-agnostic NPM package that validates and documents your environment variables from your .env.example file, preventing runtime errors before they happen.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published