gen-envex
v1.0.2
Published
CLI tool to generate a .env.example from your .env file — strips all values, keeps keys safe to commit
Maintainers
Readme
gen-envex - Generate .env.example
🔒 Automatically generate a
.env.examplefrom your.envfile by removing all secret values while preserving variable names, comments, and formatting.
🔗 Quick Links
- Repository: https://github.com/AniketDey06/gen-envex
- npm: https://www.npmjs.com/package/gen-envex
✨ Features
- 🔐 Removes all secret values automatically
- 📝 Preserves comments and blank lines
- 📄 Keeps environment variable names intact
- ⚡ Simple CLI with zero configuration
- 📂 Supports custom input and output files
- 🖥️ Works on Windows, macOS, and Linux
📖 Why use gen-envex?
Your .env file contains sensitive information such as API keys, database passwords, and tokens, so it should never be committed to Git.
However, your teammates still need to know which environment variables are required.
gen-envex automatically creates a safe .env.example by stripping all values while preserving the structure of your original file.
📥 Example
Input (.env)
# Database configuration
DB_HOST=localhost
DB_PORT=5432
DB_PASSWORD=supersecret123
# API Keys
STRIPE_SECRET_KEY=sk_live_abc123
NEXT_PUBLIC_API_URL=https://api.example.comOutput (.env.example)
# Database configuration
DB_HOST=
DB_PORT=
DB_PASSWORD=
# API Keys
STRIPE_SECRET_KEY=
NEXT_PUBLIC_API_URL=📦 Installation
Install globally
npm install -g gen-envexInstall as a development dependency
npm install --save-dev gen-envexUse without installing
npx gen-envex📄 Standalone Script
If you prefer not to install gen-envex, you can use the standalone script instead.
Simply download or copy generate-env-example.js into your project and run it directly with Node.js.
Code Link - https://github.com/AniketDey06/gen-envex/blob/main/generate-env-example.js
node generate-env-example.jsYou can also integrate it into your project's package.json scripts.
{
"scripts": {
"gen:env": "node generate-env-example.js",
"dev": "node generate-env-example.js && next dev"
}
}This keeps your .env.example up to date every time you start your development server—without installing the CLI globally or as a project dependency.
🚀 Usage
Basic usage
Generate .env.example from .env in the current directory.
gen-envexor
npx gen-envexCustom input and output
gen-envex --input .env.local --output .env.examplegen-envex --input config/.env --output config/.env.example📜 package.json Scripts
Generate manually
{
"scripts": {
"gen:env": "gen-envex"
}
}Run:
npm run gen:envor
pnpm gen:envor
yarn gen:envGenerate automatically before development
{
"scripts": {
"dev": "gen-envex && next dev"
}
}Now every time you run:
npm run dev(or pnpm dev / yarn dev), your .env.example will always stay up to date.
⚙️ CLI Options
| Option | Description |
|---------|-------------|
| --input | Path to the source .env file |
| --output | Path where .env.example will be generated |
Example:
gen-envex --input .env.local --output .env.example✅ Behavior
gen-envex preserves your file structure while removing sensitive values.
- ✅ Removes all environment variable values
- ✅ Preserves comments (
# ...) - ✅ Preserves blank lines
- ✅ Preserves variable order
- ✅ Ignores invalid lines without
= - ✅ Supports both Unix (
\n) and Windows (\r\n) line endings
🤝 Contributing
Contributions are welcome!
If you'd like to improve gen-envex, feel free to:
Open an issue
Submit a pull request
Suggest new features
Repository: https://github.com/AniketDey06/gen-envex (Do leave a ⭐)
👨💻 Authors
- Aniket Dey - https://aniketdey.in
- Arun Mondal - https://github.com/ArunKM-Git
📄 License
This project is licensed under the MIT License.
