simple-env-reader
v1.0.1
Published
Safely load environment variables in Node.js with fallback support.
Downloads
9
Maintainers
Readme
📦 simple-env-reader
A lightweight utility to safely read environment variables in Node.js with fallback support and strict checks.
📦 Install
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' }