0.0.3 ⢠Published 4 months ago
@flyinghawk/envguard v0.0.3
envguard
A simple and type-safe way to manage your environment variables in Node.js and Bun projects.
- Schema validation
- Required variables and default values
š¦ Installation
bun add @flyinghawk/envguard zod
# or
npm install @flyinghawk/envguard zod
š ļø Usage
- Create a schema file
// env.ts
import { loadDotEnv } from "@flyinghawk/envguard";
const envSchema = z.object({
API_KEY: z.string(),
port: z.coerce.number(), // will convert "4000" to 4000
});
// Pass the schema and optionally the path to loadEnv
const env = loadDotEnv(envSchema); // or loadDotEnv(schema, "../../.env")
// returns the env else throws the error
- Load and use environment variables
console.log(env.PORT) // 3000 (or from .env)
console.log(env.DB_URL) // must be present
š» Contribute
Looking for help to improve and maintain this project. PRs welcome!