```Show HN: Dotenv-Diff v3.0.0```
Show HN: Dotenv-Diff v3.0.0

原始链接: https://github.com/Chrilleweb/dotenv-diff

**dotenv-diff** 是一款功能强大的命令行工具,旨在确保您的环境变量保持一致、安全且无误。它通过扫描代码库,在环境变量进入生产环境之前识别缺失、未使用、重复或配置错误的变量。 主要功能包括: * **框架支持:** 原生集成 SvelteKit、Next.js 和 Nuxt,并针对特定框架的变量误用提供内置警告。 * **CI/CD 与 Git Hooks:** 可轻松在开发流水线中自动执行检查,以强制执行配置标准。 * **智能管理:** 支持设置令牌过期时间,通过代码注释忽略特定警告,并使用 `--baseline` 功能在现有项目中引入该工具,而无需先清理历史遗留问题。 * **深度检测:** 使用 `--explain` 命令可精确追踪变量在项目中的定义及使用位置。 * **可扩展性:** 非常适合 Monorepo(单仓库)架构,允许包含共享包并忽略特定环境的变量。 通过及早发现问题,**dotenv-diff** 能够改善团队协作,防止运行时错误,并降低敏感数据泄露的风险。它是现代 JavaScript 和 TypeScript 环境中不可或缺的工具,有助于开发者维护可靠的配置管理。

Hacker News 最新 | 往期 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: Dotenv-Diff v3.0.0 (github.com/chrilleweb) 3 分,由 chrillemn 发布于 2 小时前 | 隐藏 | 往期 | 收藏 | 讨论 距离我上次发布 dotenv-diff 的更新已经过去很久了,自那以后增加了许多新功能。 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

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.

First-class support for SvelteKit, Next.js, and Nuxt. Also works well in modern JavaScript/TypeScript projects and frameworks like Node.js and Vue — or any other setup where you want reliable .env file comparison.

Coverage Status npm version npm downloads

✨ Featured in awesome-cli-apps - A curated list of awesome CLI applications


Demo


  • Ensure all required environment variables are defined before deploying
  • Catch missing or misconfigured variables early in development
  • Improve collaboration by keeping teams aligned on required variables
  • Reduce the risk of committing sensitive data
  • Scale easily for monorepos and multi-environment setups

→ See Capabilities Documentation for details on what the scanner checks for and how it works.


Generate a default configuration file:

→ See Configuration Documentation for more details.


Git hooks and CI/CD Integration

Easily integrate dotenv-diff into your Git hooks or CI/CD pipelines to enforce environment variable consistency.

→ See Git Hooks Documentation for more details.

Framework-Specific Warnings

In SvelteKit, Next.js, and Nuxt projects, dotenv-diff detects framework-specific environment variable misuses.

Example warning:

Framework issues (Sveltekit):
  - PUBLIC_API_URL (src/routes/+page.ts:1)
    → $env/dynamic/private variables must not start with "PUBLIC_"

→ See Framework Documentation for more details.

You can ignore specific environment variable warnings by adding comments in your code. For example:

const apiKey = process.env.API_KEY; // dotenv-diff-ignore

This is helpful when you know a specific warning is safe in your source code.

→ See Ignore Comments Documentation for more details.


Add expiration metadata to your environment variables to get warnings when they are about to expire. For example, in your .env file:

# @expire 2025-12-31
API_TOKEN=

→ See Expiration Documentation for more details.


Suppress existing warnings (--baseline)

Adopt dotenv-diff in projects that already have known warnings by recording the current state into a baseline file. Future runs will only report newly introduced issues:

→ See Baseline Documentation for more details.


Explain a variable (--explain)

Inspect a specific environment variable to see where it is defined, where it is used in the codebase, and its overall status:

dotenv-diff --explain DATABASE_URL

→ See --explain Documentation for more details.


In monorepos with multiple apps and packages, you can include shared folders:

{
  "scripts": {
    "dotenv-diff": "dotenv-diff --example .env.example --include-files '../../packages/**/*' --ignore VITE_MODE"
  }
}

→ See Monorepo Documentation for more details.

This will:

  • Scan the current app
  • Include shared packages
  • Ignore variables used only in specific environments

  • 0 → No errors
  • 1 → Errors found (or warnings in strict mode)

→ See dotenv-diff Documentation for full documentation


Issues and pull requests are welcome.
→ See CONTRIBUTING for details.

Thanks to these amazing people for contributing to this project:


Licensed under the MIT license.

Created by chrilleweb

联系我们 contact @ memedata.com