0.0.3 • Published 4 months ago

@flyinghawk/envguard v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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

  1. 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
  1. 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!

0.0.3

4 months ago

0.0.2

5 months ago

0.0.1

5 months ago