@muerteseguraz/envguard
v1.0.1
Published
Simple .env schema validator with type safety
Maintainers
Readme
envguard
🛡️ Simple
.envschema validator with type safety, defaults, and clear errors.
✨ Features
- ✅ Schema-based environment validation
- ✅ Type-safe (TS friendly)
- ✅ Defaults and enum support
- ✅ Clean error messages
- ✅ Zero deps (except
dotenv)
📦 Installation
npm i envguard🚀 Usage
// envguard.config.ts
import { defineEnv } from 'envguard';
export default defineEnv({
API_KEY: { type: 'string' },
PORT: { type: 'number', default: 3000 },
NODE_ENV: { type: 'enum', values: ['development', 'production'], default: 'development' },
DEBUG: { type: 'boolean', default: false }
});// index.ts
import config from './envguard.config';
import { loadEnv } from 'envguard';
const env = loadEnv(config);
console.log(env.PORT); // → 3000 (number)❌ Errors
If variables are missing or invalid, you'll get clean, readable errors:
Missing required environment variable: API_KEY
Invalid number for PORT: abc
Invalid value for NODE_ENV. Expected one of: development, production🧪 Testing
npx vitest run🛠️ License
MIT © 2025 MuerteSeguraZ
---
