$npx -y skills add girijashankarj/cursor-handbook --skill env-file-generatorScan codebase for environment variable references and generate a complete .env.example file with safe placeholders. Use when the user asks to create or update .env.example or audit env var usage.
| 1 | # Skill: Env File Generator |
| 2 | |
| 3 | Scan source code for `process.env.*` references and produce a comprehensive `.env.example` with documentation and safe placeholder values. |
| 4 | |
| 5 | ## Trigger |
| 6 | When the user asks to create `.env.example`, audit environment variables, or ensure all required env vars are documented. |
| 7 | |
| 8 | ## Prerequisites |
| 9 | - [ ] Access to project source code |
| 10 | - [ ] Knowledge of which env vars are required vs optional |
| 11 | |
| 12 | ## Steps |
| 13 | |
| 14 | ### Step 1: Scan for Environment Variable References |
| 15 | - [ ] Search for `process.env.` patterns across source files |
| 16 | - [ ] Search for `os.environ` / `os.getenv` (Python projects) |
| 17 | - [ ] Search for `System.getenv` (Java projects) |
| 18 | - [ ] Check existing config loader files for env var mappings |
| 19 | - [ ] Check Docker/compose files for `environment:` and `${VAR}` references |
| 20 | - [ ] Check CI/CD config for required secrets |
| 21 | |
| 22 | ### Step 2: Catalog Variables |
| 23 | For each variable found: |
| 24 | - [ ] Name (e.g., `DB_PASSWORD`) |
| 25 | - [ ] Where it's used (file and line) |
| 26 | - [ ] Whether it has a default value in code |
| 27 | - [ ] Whether it's required (no default, throws if missing) |
| 28 | - [ ] Data type (string, number, boolean, URL) |
| 29 | - [ ] Category (database, auth, cloud, feature flags, etc.) |
| 30 | |
| 31 | ### Step 3: Classify Sensitivity |
| 32 | |
| 33 | | Level | Examples | Placeholder Format | |
| 34 | |-------|---------|-------------------| |
| 35 | | **Secret** | `DB_PASSWORD`, `JWT_SECRET`, `API_KEY` | `your-secret-here` | |
| 36 | | **Infrastructure** | `DB_HOST`, `REDIS_URL`, `S3_BUCKET` | `localhost` / descriptive example | |
| 37 | | **Config** | `PORT`, `LOG_LEVEL`, `NODE_ENV` | Actual default value | |
| 38 | | **Feature** | `ENABLE_FEATURE_X`, `MAX_RETRIES` | `true` / `false` / number | |
| 39 | |
| 40 | ### Step 4: Generate .env.example |
| 41 | |
| 42 | ```bash |
| 43 | # ============================================ |
| 44 | # {{CONFIG.project.name}} Environment Variables |
| 45 | # ============================================ |
| 46 | # Copy this file to .env and fill in the values |
| 47 | # NEVER commit .env to version control |
| 48 | # ============================================ |
| 49 | |
| 50 | # --------------------- |
| 51 | # Application |
| 52 | # --------------------- |
| 53 | NODE_ENV=development |
| 54 | PORT=3000 |
| 55 | LOG_LEVEL=info |
| 56 | |
| 57 | # --------------------- |
| 58 | # Database |
| 59 | # --------------------- |
| 60 | DB_HOST=localhost |
| 61 | DB_PORT=5432 |
| 62 | DB_NAME={{CONFIG.project.name}} |
| 63 | DB_USERNAME=your-db-username |
| 64 | DB_PASSWORD=your-db-password |
| 65 | |
| 66 | # --------------------- |
| 67 | # Authentication |
| 68 | # --------------------- |
| 69 | JWT_SECRET=your-jwt-secret-min-32-chars |
| 70 | JWT_EXPIRY=15m |
| 71 | |
| 72 | # --------------------- |
| 73 | # Cloud / AWS |
| 74 | # --------------------- |
| 75 | AWS_REGION=us-east-1 |
| 76 | AWS_ACCESS_KEY_ID=your-access-key |
| 77 | AWS_SECRET_ACCESS_KEY=your-secret-key |
| 78 | |
| 79 | # --------------------- |
| 80 | # External Services |
| 81 | # --------------------- |
| 82 | # REDIS_URL=redis://localhost:6379 |
| 83 | # SMTP_HOST=smtp.example.com |
| 84 | ``` |
| 85 | |
| 86 | ### Step 5: Cross-Reference |
| 87 | - [ ] Compare with existing `.env.example` (if any) to find new/removed vars |
| 88 | - [ ] Check `.gitignore` includes `.env` (add if missing) |
| 89 | - [ ] Verify config validation code matches the env var list |
| 90 | - [ ] Flag any env vars in code that are NOT in `.env.example` |
| 91 | |
| 92 | ### Step 6: Generate Validation Code (Optional) |
| 93 | ```typescript |
| 94 | const required = ['DB_PASSWORD', 'JWT_SECRET'] as const; |
| 95 | for (const key of required) { |
| 96 | if (!process.env[key]) { |
| 97 | throw new Error(`Missing required environment variable: ${key}`); |
| 98 | } |
| 99 | } |
| 100 | ``` |
| 101 | |
| 102 | ### Step 7: Output |
| 103 | - [ ] Present `.env.example` content |
| 104 | - [ ] List any discrepancies (vars in code but not in example, or vice versa) |
| 105 | - [ ] Note which vars are required at startup |
| 106 | |
| 107 | ## Rules |
| 108 | - **NEVER** put real secret values in `.env.example` |
| 109 | - **ALWAYS** use safe placeholder values (`your-xxx-here`, `localhost`, defaults) |
| 110 | - **ALWAYS** include comments explaining each section |
| 111 | - **ALWAYS** verify `.env` is in `.gitignore` |
| 112 | - Group variables by category with section headers |
| 113 | - Mark optional variables with comments (prefix with `#`) |
| 114 | - Include type hints in comments where ambiguous |
| 115 | |
| 116 | ## Completion |
| 117 | Complete `.env.example` with all environment variables, grouped by category, with safe placeholders and documentation. |
| 118 | |
| 119 | ## If a Step Fails |
| 120 | - **Too many vars (>50):** Group by service/module, add a table of contents comment |
| 121 | - **Dynamic env var names:** Flag for manual review (e.g., `process.env[varName]`) |
| 122 | - **Can't determine required vs optional:** Default to required, flag for user review |
| 123 | - **Existing .env.example out of date:** Show diff of changes (added/removed vars) |