🔐 dotenv-required
Ensure required environment variables are defined in process.env
.
Perfect for projects using .env
files with libraries like dotenv
. Prevents your app from running with missing configuration.
📦 Installation
Using npm
npm install dotenv-required
Using yarn
yarn add dotenv-required
🚀 Usage
Example with dotenv
require("dotenv").config();
const envRequire = require("dotenv-required");
envRequire(["API_KEY", "DB_HOST", "SECRET_TOKEN"]);
Without dotenv
process.env.API_KEY = "123";
envRequire(["API_KEY", "SECRET"]);
⚙️ Options
keys | string[] | ✅ | List of environment variable names to check |
📤 Output Example
If required variables are missing:
Error: Missing required environment variables: SECRET, DB_HOST
Otherwise, nothing happens — the app continues.
🧪 Run Test
node test.js
🪪 License
MIT