node-verify-env
v1.0.0
Published
Verify all environment variables used in the project exist in .env
Maintainers
Readme
✅ node-verify-env
Verify that all environment variables used in your Node.js project exist in your .env file.
Catch missing configuration before runtime and avoid surprises in production.
📦 Installation
# Using npm
npm install --save-dev node-verify-env
# Using yarn
yarn add --dev node-verify-env🚀 Usage
✅ CLI
Run in your project root:
npx node-verify-envExample Output:
Scanning for environment variables...
Found 3 env variables in code.
❌ Missing environment variables in .env file:
- DB_PASSWORD
- API_KEYIf all variables exist:
✅ All required environment variables are present.CLI Options
| Option | Description |
|--------------------|--------------------------------------------|
| --project-path | Path to scan (default: current directory) |
| --env-path | Path to .env file (default: .env) |
| --ignore | Comma-separated vars to ignore |
Example:
npx node-verify-env --project-path ./src --env-path ./config/.env --ignore OPTIONAL_VAR,DEBUG✅ Programmatic API
import verifyEnv from "node-verify-env";
await verifyEnv({
projectPath: "./src", // Directory to scan (default: process.cwd())
envPath: ".env", // Path to .env file (default: ".env")
ignore: ["OPTIONAL_VAR"] // Variables to ignore
});📄 Example
.env
DB_HOST=localhost
DB_USER=rootindex.js
console.log(process.env.DB_HOST);
console.log(process.env.DB_PASSWORD); // Missing in .env
console.log(process.env.SERVICE_KEY); // Missing in .envRun:
npx node-verify-envOutput:
Scanning for environment variables...
Found 3 env variables in code.
❌ Missing environment variables in .env file:
- DB_PASSWORD
- SERVICE_KEY🔍 How It Works
- Scans your code for
process.env.VAR_NAME - Collects all variable names
- Reads your
.envfile - Prints missing variables
- Exits with status code
1if any variables are missing (perfect for CI/CD)
🛠 Features
✔ Works with any Node.js project
✔ Detects missing env vars before runtime
✔ CLI + programmatic usage
✔ TypeScript support
✔ Great for CI/CD pipelines
📦 Add to CI/CD
Example for GitHub Actions:
- name: Verify Environment Variables
run: npx node-verify-env📌 Roadmap
- [ ] Add support for
import.meta.env(Vite/Frontend projects) - [ ] Add config file support for custom settings
- [ ] Add option for
.env.examplevalidation
🛠 Contributing
Pull requests are welcome! For major changes, open an issue first to discuss what you would like to change.
