find-env-vars
v1.0.1
Published
A simple and efficient Node.js utility tool that scans your entire project directory to find all environment variables used in your JavaScript and TypeScript files, then automatically generates a `.env.example` file.
Readme
find-env-vars
A simple and efficient Node.js utility tool that scans your entire project directory to find all environment variables used in your JavaScript and TypeScript files, then automatically generates a .env.example file.
Features
- 🔍 Deep Scanning: Recursively scans all subdirectories in your project (no depth limit)
- 📁 Smart Filtering: Automatically skips
node_modules,dist,build,out,.next,venvand.gitdirectories - 🎯 Pattern Detection: Finds all
process.env.VARIABLE_NAMEpatterns in.js,.ts,.jsx,.tsx,.mjs,.cjs,.vue, and.sveltefiles - 📝 Auto-Generation: Creates a
.env.examplefile with all discovered variables - ⚡ Fast & Lightweight: Built with async/await for optimal performance
- 🛡️ Error Handling: Gracefully handles permission errors and continues scanning
Installation
Install globally via npm:
npm install -g find-env-varsOr use directly with npx (no installation required):
npx find-env-varsUsage
Simply run the command in your project root directory:
find-env-varsThe tool will:
- Scan all
.js,.ts,.jsx,.tsx,.mjs,.cjs,.vue, and.sveltefiles in your project - Extract all environment variables used (e.g.,
process.env.PORT) - Display a sorted list of found variables
- Generate a
.env.examplefile in the current directory
Example Output
Starting ENV variable scan in: /path/to/your/project
Scanning all child directory levels...
--- Scan Complete ---
✅ Found 5 unique environment variables:
Environment Variables: [ 'API_KEY', 'DATABASE_URL', 'NODE_ENV', 'PORT', 'SECRET_KEY' ]
.env.example content:
API_KEY=
DATABASE_URL=
NODE_ENV=
PORT=
SECRET_KEY=
.env.example file created successfully.
---------------------How It Works
The tool uses a regular expression pattern to match process.env.VARIABLE_NAME throughout your codebase:
- Recursively traverses all directories from where the command is run
- Skips common directories like
node_modulesand.git - Reads
.js,.ts,.jsx,.tsx,.mjs,.cjs,.vue, and.sveltefiles only - Extracts unique variable names
- Generates a template
.env.examplefile with empty values
Use Cases
Perfect for:
- 🚀 New Team Members: Help them quickly set up required environment variables
- 📦 Open Source Projects: Provide clear documentation of needed environment variables
- 🔄 Project Handoffs: Ensure all environment variables are documented
- ✅ CI/CD Setup: Verify all required environment variables are configured
- 🧹 Codebase Audit: Discover which environment variables your project actually uses
Requirements
- Node.js 14.x or higher
- Read permissions for the directories being scanned
Technical Details
- Language: JavaScript (Node.js)
- Module System: CommonJS
- Dependencies: None (uses only Node.js built-in modules)
- Async: Built with modern async/await patterns
Limitations
- Only detects the pattern
process.env.VARIABLE_NAME - Does not detect dynamically constructed variable names (e.g.,
process.env[variableName]) - Skips files/directories where permission errors occur
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Author
Mehedi Siam
- Portfolio: mehedisiam.com
- GitHub: @mehedihsiam
License
ISC
Support
If you find this tool helpful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs or requesting features
- 📢 Sharing it with others who might find it useful
Made with ❤️ by Mehedi Siam
