@caxy/dotenv-updater

中文文档
1.0.11发布于 2025/09/05MIT近 30 天下载 1905

Keep your gitignored local .env file up to date with the dist file.

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Configuration
  4. Options

npm (scoped) npm

Dotenv Updater

Dotenv Updater is a module that keeps your local, gitignored, .env files up to date with the latest variables defined in a dist/example file, like .env.example.

It compares your .env file with the .env.example (or other file specified in config), and if there any variables missing from your .env file it will interactively prompt you for their values on the command line, and update your .env file for you.

Install

# with npm
npm install --save-dev @caxy/dotenv-updater

# or with Yarn
yarn add --dev @caxy/dotenv-updater

Usage

The primary use-case is to run this script alongside your other npm/Yarn scripts defined in your package.json.

For example, you can add calls to dotenv-updater at the beginning of your commonly run scripts, so that you can ensure you'll always have an up-to-date env file.

# in your package.json

"scripts": {
  "start": "dotenv-updater && node dist/index.js",
  "build": "dotenv-updater && ..."
},
...

You can also run it manually from the command line at the root of the project (or anywhere if installed globally):

dotenv-updater

Configuration

You can add configuration in your package.json file to modify some of the default settings, which you will definitely want to do if your dist file is not named .env.example.

Below shows the configuration options available and their default values.

# in your package.json

{
  # ...

  "dotenvUpdater": {
    "envFile": ".env",
    "distFile": ".env.example",
    "checkExtraVars": true
  }
}

Options

Option nameDescriptionDefault value
envFileThe name of the local env file. This is the file that will be updated with new variables found in the distFile. This file is often ignored and excluded from source control since it may contain sensitive information.".env"
distFileThe name of the "dist" env file, which serves as the empty template for the environment variables that are available to be defined. This file is often tracked in the repository and has default/placeholder values.".env.example"
checkExtraVarsBoolean flag to enable/disable the "check extra vars" feature. When set to true, the script will check to see if there are any variables defined in the envFile that are not defined in the distFile. If any are found, a message will be printed to the console indicating that there are extra variables not found in the dist file and will include which variables.

The idea here is that if there are any extra variables in the envFile, they might be outdated / no longer used and can be removed, or it might be an indication that the distFile is missing some variables that are used and they should be updated with those.

This will not remove any variables from the envFile, it will only log a message to the console.
true

版本与发布记录

@caxy/dotenv-updater 共发布 11 个版本,首次发布于 2019/08/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.11latest2025/09/051.2 年前
1.0.92019/11/286 年前
1.0.82019/11/286 年前
1.0.72019/11/286 年前
1.0.62019/08/277 年前
1.0.52019/08/277 年前

其他发布通道:1.0.3 → 1.0.3,1.0.4 → 1.0.4。

关于 @caxy/dotenv-updater 的常见问题

@caxy/dotenv-updater 是什么?

Keep your gitignored local .env file up to date with the dist file.

如何安装 @caxy/dotenv-updater?

在项目目录运行 npm install @caxy/dotenv-updater,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 dotenv-updater,可以用 npx dotenv-updater 直接运行。

@caxy/dotenv-updater 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/caxy__dotenv-updater 是否存在。

@caxy/dotenv-updater 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@caxy/dotenv-updater 可以商用吗?

@caxy/dotenv-updater 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@caxy/dotenv-updater 的下载量有多少?

根据 npm 官方下载统计,@caxy/dotenv-updater 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,905 次,日均约 64 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@caxy/dotenv-updater 还在维护吗?

最新版本 1.0.11 发布于 2025/09/05(1.2 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/08/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。