secure-env-guardian
v1.1.0
Published
Simple environment variable validation for Node.js
Maintainers
Readme
secure-env-guardian
Simple and reliable environment variable validation for Node.js.
secure-env-guardian helps ensure required environment variables exist and are correctly typed before your application starts.
Installation
npm i secure-env-guardianQuick Example
import { EnvGuard } from "secure-env-guardian";
const env = EnvGuard.validate({
PORT: { type: "number", required: true },
DATABASE_URL: { type: "string", required: true },
DEBUG: { type: "boolean", default: false },
});
console.log(env.PORT);Example .env
PORT=3000
DATABASE_URL=mongodb://localhost:27017
DEBUG=trueSupported Types
secure-env-guardian supports the following types:
- string
- number
- boolean
Example:
EnvGuard.validate({
PORT: { type: "number" },
DEBUG: { type: "boolean" },
});Default Values
EnvGuard.validate({
NODE_ENV: { type: "string", default: "development" },
});Error Handling
If validation fails, EnvGuard throws a descriptive error.
Example:
Missing environment variable: DATABASE_URLWhy secure-env-guardian?
Many Node.js applications fail at runtime due to missing environment variables.
secure-env-guardian ensures configuration errors are caught early during application startup.
Roadmap
Future features planned:
- enum validation
- CLI support
.env.examplegenerator- TypeScript schema inference
Contributing
Contributions are welcome.
- Fork the repository
- Create a feature branch
- Submit a pull request
License
MIT
