Overview
Thegenerate_env_template tool scans the entire codebase and generates a complete .env.example file from scratch. It automatically:
- Groups variables by detected cluster (Database, API, Authentication, etc.)
- Adds inferred descriptions for each variable
- Marks which variables are required vs optional
- Generates sensible placeholder values
Parameters
Path to the project directory. Defaults to current working directory.
Path to write the generated .env.example file. If not provided, only returns the content without writing to disk.
Response
The generated .env.example file content
Total number of variables included in the template
Number of variable clusters (groups) detected
Number of required variables (marked with [REQUIRED])
Number of optional variables (marked with [OPTIONAL])
Absolute path where the file was written (only present if outputPath was provided)
Scan metadata
Example Response
Generated Content Example
Usage Example
Generate and write to file:Variable Clustering
Variables are automatically grouped into clusters:- Server: PORT, HOST, NODE_ENV, BASE_URL
- Database: DATABASE_URL, DB_, POSTGRES_, MYSQL_*
- Caching: REDIS_, MEMCACHED_
- Authentication: JWT_, SESSION_, AUTH_*
- API: API_KEY, API_SECRET, *_API_KEY
- Email: SMTP_, SENDGRID_, MAILGUN_*
- Monitoring: SENTRY_, DATADOG_, NEW_RELIC_*
- AWS: AWS_*
- Google Cloud: GOOGLE_, GCP_
- Azure: AZURE_*
- Payment: STRIPE_, PAYPAL_
- Framework: Framework-specific variables
- Secrets: Variables with SECRET, PASSWORD, TOKEN, KEY
- Other: Uncategorized variables
Description Generation
Descriptions are automatically generated using:- Known patterns: Common variables like DATABASE_URL, API_KEY get standard descriptions
- Service prefixes: AWS_, STRIPE_, etc. get service-specific descriptions
- Name analysis: Variable name parts are analyzed to generate meaningful descriptions
- Suffix patterns: _URL, _HOST, _PORT, _KEY get context-appropriate descriptions
Placeholder Values
Sensible placeholders are generated based on variable type:- Secrets (SECRET, PASSWORD, TOKEN, KEY):
your-secret-here - URLs:
https://example.com - Hosts:
localhost - Ports:
3000 - Emails:
[email protected] - NODE_ENV:
development - LOG_LEVEL:
info - DEBUG:
false - With defaults: Empty string
- Other:
your-value-here
Required vs Optional
Variables are marked as required if:- They have no default value in code AND
- They match critical patterns (DATABASE*, DB_, REDIS, *SECRET, API_KEY)
Use Cases
- New Projects: Generate initial .env.example from existing code
- Documentation: Create comprehensive environment variable documentation
- Onboarding: Help new developers understand all required configuration
- Migration: Update .env.example when adding new variables to code
- Auditing: Ensure .env.example is complete and up-to-date