|
1 | 1 | # dotenv-diff |
2 | 2 |
|
3 | | -> This is the cli package for [dotenv-diff](https://www.npmjs.com/package/dotenv-diff) |
| 3 | +Scan your codebase to detect every environment variable reference. It helps you catch missing, unused, duplicated, and misused variables early, before they cause runtime errors. |
4 | 4 |
|
5 | | -[](https://www.npmjs.com/package/dotenv-diff) |
6 | | -[](https://www.npmjs.com/package/dotenv-diff) |
| 5 | +First-class support for SvelteKit and Next.js. Also works well in modern JavaScript/TypeScript projects and frameworks like Node.js, Nuxt, and Vue — or any other setup where you want reliable .env file comparison. |
| 6 | + |
| 7 | +[](https://codecov.io/gh/Chrilleweb/dotenv-diff) |
| 8 | +[](https://www.npmjs.com/package/dotenv-diff) |
| 9 | +[](https://www.npmjs.com/package/dotenv-diff) |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Warnings & errors detection |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +### Clean / successful scan |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Why dotenv-diff? |
| 24 | + |
| 25 | +- Ensure all required environment variables are defined before deploying |
| 26 | +- Catch missing or misconfigured variables early in development |
| 27 | +- Improve collaboration by keeping teams aligned on required variables |
| 28 | +- Reduce the risk of committing sensitive data |
| 29 | +- Scale easily for monorepos and multi-environment setups |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## How It Works |
| 34 | + |
| 35 | +→ See [Capabilities Documentation](./docs/capabilities.md) for details on what the scanner checks for and how it works. |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## Configuration (`--init`) |
| 40 | + |
| 41 | +Generate a default configuration file: |
| 42 | + |
| 43 | +```bash |
| 44 | +dotenv-diff --init |
| 45 | +``` |
| 46 | + |
| 47 | +→ See [Configuration Documentation](./docs/configuration_and_flags.md#configuration-file) for more details. |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## Git hooks and CI/CD Integration |
| 52 | + |
| 53 | +Easily integrate dotenv-diff into your Git hooks or CI/CD pipelines to enforce environment variable consistency. |
| 54 | + |
| 55 | +→ See [Git Hooks Documentation](./docs/git_hooks_ci.md) for more details. |
| 56 | + |
| 57 | +## Framework-Specific Warnings |
| 58 | + |
| 59 | +In SvelteKit and Next.js projects, dotenv-diff detects framework-specific |
| 60 | +environment variable misuses. |
| 61 | + |
| 62 | +Example warning: |
| 63 | + |
| 64 | +```bash |
| 65 | +Framework issues (Sveltekit): |
| 66 | + - PUBLIC_URL (src/routes/+page.ts:1) |
| 67 | + → Variables accessed through import.meta.env must start with "VITE_" |
| 68 | +``` |
| 69 | + |
| 70 | +→ See [Framework Documentation](./docs/frameworks/index.md) for more details. |
| 71 | + |
| 72 | +## Ignore Comments |
| 73 | + |
| 74 | +You can ignore specific environment variable warnings by adding comments in your code. For example: |
| 75 | + |
| 76 | +```javascript |
| 77 | +const apiKey = process.env.API_KEY; // dotenv-diff-ignore |
| 78 | +``` |
| 79 | + |
| 80 | +This is helpful when you know a specific warning is safe in your source code. |
| 81 | + |
| 82 | +→ See [Ignore Comments Documentation](./docs/ignore_comments.md) for more details. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## Expiration Warnings |
| 87 | + |
| 88 | +Add expiration metadata to your environment variables to get warnings when they are about to expire. For example, in your `.env` file: |
| 89 | + |
| 90 | +```bash |
| 91 | +# @expire 2025-12-31 |
| 92 | +API_TOKEN= |
| 93 | +``` |
| 94 | + |
| 95 | +→ See [Expiration Documentation](./docs/expiration_warnings.md) for more details. |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Monorepo support |
| 100 | + |
| 101 | +In monorepos with multiple apps and packages, you can include shared folders: |
| 102 | + |
| 103 | +```json |
| 104 | +{ |
| 105 | + "scripts": { |
| 106 | + "dotenv-diff": "dotenv-diff --example .env.example --include-files '../../packages/**/*' --ignore VITE_MODE" |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +→ See [Monorepo Documentation](./docs/monorepo_support.md) for more details. |
| 112 | + |
| 113 | +This will: |
| 114 | + |
| 115 | +- Scan the current app |
| 116 | +- Include shared packages |
| 117 | +- Ignore variables used only in specific environments |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Exit Codes |
| 122 | + |
| 123 | +- `0` → No errors |
| 124 | +- `1` → Errors found (or warnings in strict mode) |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Documentation |
| 129 | + |
| 130 | +→ See [dotenv-diff Documentation](./docs/index.md) for full documentation |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## Contributing |
| 135 | + |
| 136 | +Issues and pull requests are welcome. |
| 137 | +→ See [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 138 | + |
| 139 | +Thanks to these amazing people for contributing to this project: |
| 140 | + |
| 141 | +<a href="https://github.com/Chrilleweb/dotenv-diff/graphs/contributors"> |
| 142 | + <img src="https://contrib.rocks/image?repo=Chrilleweb/dotenv-diff" /> |
| 143 | +</a> |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## License |
| 148 | + |
| 149 | +Licensed under the [MIT](LICENSE) license. |
| 150 | + |
| 151 | +Created by [chrilleweb](https://github.com/chrilleweb) |
0 commit comments