UNPKG

simple-env-reader

Version:

Safely load environment variables in Node.js with fallback support.

47 lines (31 loc) 822 B
# 📦 simple-env-reader A lightweight utility to safely read environment variables in Node.js with fallback support and strict checks. --- ## 📦 Install ```bash npm install simple-env-reader ``` ## 🔧 Why Use It? - Safe access to `process.env` - Throws error if any key is missing - Optional fallback values - Dependency-free, simple, and production-safe --- ## 🚀 Usage ``` // index.js require("dotenv").config(); // Optional const { getEnv } = require("simple-env-reader"); const env = getEnv(["PORT", "DB_URL"], { PORT: "3000" }); console.log("Loaded Env:", env); ``` ## ✅ Example .env ``` DB_URL=mongodb://localhost:27017/myapp ``` ## 🖥️ Output ``` Loaded Env: { PORT: '3000', DB_URL: 'mongodb://localhost:27017/myapp' } ```