Loading...
Loading...
Compare original and translation side by side
dotenvrundotenvx rundotenvx encrypt.envdotenvx setgetdotenvx decrypt.env-fDOTENV_PRIVATE_KEY_*dotenvrundotenvx rundotenvx encryptdotenvx setgetdotenvx decryptDOTENV_PRIVATE_KEY_*undefinedundefined
For Node.js, also usable as a library:
```js
require('@dotenvx/dotenvx').config()
// or: import '@dotenvx/dotenvx/config'
对于Node.js,也可作为库使用:
```js
require('@dotenvx/dotenvx').config()
// 或:import '@dotenvx/dotenvx/config'dotenvx rundotenvx run.envdotenvx run -- <command>| Flag | Description |
|---|---|
| Specify env file(s). Repeatable. Default: |
| Set inline env var |
| Later files/values override earlier ones (default: first wins) |
| Exit code 1 on any error (missing file, decrypt failure) |
| Ignore specific errors (e.g., |
| Load files using Next.js or dotenv-flow convention |
| Specify path to |
| Suppress all output except errors |
| Verbose logging |
| Debug-level logging |
| Set log level: |
undefineddotenvx run -- <command>| 参数 | 描述 |
|---|---|
| 指定.env文件,可重复使用。默认值: |
| 设置内联环境变量 |
| 后续文件/值覆盖之前的(默认:先出现的优先级更高) |
| 出现任何错误时以退出码1终止(文件缺失、解密失败等) |
| 忽略特定错误(例如: |
| 按照Next.js或dotenv-flow的约定加载文件 |
| 指定 |
| 除错误外抑制所有输出 |
| 详细日志输出 |
| 调试级日志输出 |
| 设置日志级别: |
undefined
**Precedence rules:**
- By default, env vars already set in the shell take precedence over `.env` file values
- With multiple `-f` files, the first file's value wins (historic dotenv behavior)
- `--overload` reverses this: later files override earlier ones
- `--env` flag values take precedence over file values
**Variable expansion and interpolation:**
dotenvx supports `${VAR}` expansion, default values, alternate values, and command substitution inside `.env` files:
```ini
**优先级规则:**
- 默认情况下,Shell中已设置的环境变量优先级高于.env文件中的值
- 使用多个`-f`文件时,第一个文件的值优先级更高(dotenv的历史行为)
- `--overload`会反转此规则:后续文件覆盖之前的
- `--env`参数设置的值优先级高于文件中的值
**变量展开与插值:**
dotenvx支持.env文件中的`${VAR}`展开、默认值、替代值以及命令替换:
```ini
**Multiline values** are supported — wrap in double quotes:
```ini
CERT="-----BEGIN CERTIFICATE-----
MIIB...
-----END CERTIFICATE-----"
**多行值**同样支持——用双引号包裹:
```ini
CERT="-----BEGIN CERTIFICATE-----\nMIIB...\n-----END CERTIFICATE-----"dotenvx keysdotenvx keypairdotenvx statusdotenvx rotatedotenvx set--env-name.env.vaultDOTENVX_PRIVATE_KEYDOTENV_PRIVATE_KEYpip install dotenvxdotenvx.load_dotenv()dotenvx run -- python app.pydotenvx keysdotenvx keypairdotenvx statusdotenvx rotatedotenvx set--env-name.env.vaultDOTENVX_PRIVATE_KEYDOTENV_PRIVATE_KEYpip install dotenvxdotenvx.load_dotenv()dotenvx run -- python app.pydotenvx encryptdotenvx encrypt.envDOTENV_PUBLIC_KEY.envDOTENV_PRIVATE_KEY.env.keysdotenvx encrypt # encrypts .env
dotenvx encrypt -f .env.production # encrypts specific file
dotenvx encrypt --stdout # output to stdout instead of in-place.envDOTENV_PUBLIC_KEY.env.keysDOTENV_PRIVATE_KEY.envDOTENV_PUBLIC_KEYDOTENV_PRIVATE_KEYdotenvx encrypt # 加密.env
dotenvx encrypt -f .env.production # 加密指定文件
dotenvx encrypt --stdout # 输出到标准输出而非原地修改.envDOTENV_PUBLIC_KEY.env.keysDOTENV_PRIVATE_KEYdotenvx decryptdotenvx decrypt.envdotenvx decrypt # decrypts .env
dotenvx decrypt -f .env.production # decrypts specific file
dotenvx decrypt --stdout # output to stdout.env.keysDOTENV_PRIVATE_KEY*dotenvx decrypt # 解密.env
dotenvx decrypt -f .env.production # 解密指定文件
dotenvx decrypt --stdout # 输出到标准输出DOTENV_PRIVATE_KEY_*dotenvx setdotenvx set.envdotenvx set KEY value # set in .env
dotenvx set KEY value -f .env.production # set in specific file
dotenvx set KEY "multi word value" # quoted values
dotenvx set KEY value -fk .env.keys -f apps/app1/.env # monorepodotenvx set KEY value # 在.env中设置
dotenvx set KEY value -f .env.production # 在指定文件中设置
dotenvx set KEY "multi word value" # 带空格的值需加引号
dotenvx set KEY value -fk .env.keys -f apps/app1/.env # monorepo场景dotenvx getdotenvx getdotenvx get HELLO # from .env
dotenvx get HELLO -f .env.production # from specific file
dotenvx get HELLO --env HELLO=Override # from --env string
dotenvx get HELLO --overload # with overload semantics
dotenvx get HELLO --strict # exit 1 if key missing
dotenvx get HELLO --convention=nextjs # with convention
dotenvx get HELLO -fk .env.keys -f app/.env # monorepodotenvx get # all vars from .env as JSON
dotenvx get -f .env.production # all vars from specific file
dotenvx get --all # include DOTENV_PUBLIC_KEY
dotenvx get --format shell # output as KEY=value linesdotenvx get HELLO # 从.env获取
dotenvx get HELLO -f .env.production # 从指定文件获取
dotenvx get HELLO --env HELLO=Override # 从--env参数获取
dotenvx get HELLO --overload # 使用覆盖语义
dotenvx get HELLO --strict # 若密钥缺失则以退出码1终止
dotenvx get HELLO --convention=nextjs # 遵循指定约定
dotenvx get HELLO -fk .env.keys -f app/.env # monorepo场景dotenvx get # 以JSON格式获取.env中的所有变量
dotenvx get -f .env.production # 以JSON格式获取指定文件中的所有变量
dotenvx get --all # 包含DOTENV_PUBLIC_KEY
dotenvx get --format shell # 以KEY=value格式输出dotenvx keypairdotenvx keypair.envdotenvx keypair # all keypairs as JSON
dotenvx keypair DOTENV_PRIVATE_KEY # just the private key
dotenvx keypair -f .env.production # for specific file
dotenvx keypair DOTENV_PRIVATE_KEY_PRODUCTION -f .env.productiondotenvx keypair # 以JSON格式输出所有密钥对
dotenvx keypair DOTENV_PRIVATE_KEY # 仅输出私钥
dotenvx keypair -f .env.production # 输出指定文件对应的密钥对
dotenvx keypair DOTENV_PRIVATE_KEY_PRODUCTION -f .env.productionundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedDOTENV_PRIVATE_KEY_*dotenvx runundefinedDOTENV_PRIVATE_KEY_*dotenvx runundefinedundefinedundefinedundefinedundefined
---
-----convention=nextjs--convention=nextjs.env.$(NODE_ENV).local.env.local.env.$(NODE_ENV).envdotenvx run --convention=nextjs -- next dev.env.$(NODE_ENV).local.env.local.env.$(NODE_ENV).envdotenvx run --convention=nextjs -- next dev--convention=flow--convention=flowDOTENV_ENVNODE_ENVDOTENV_ENV=development dotenvx run --convention=flow -- node app.jsDOTENV_ENVNODE_ENVDOTENV_ENV=development dotenvx run --convention=flow -- node app.js-fk.env.keysundefined-fk.env.keysundefined
---
---FROM node:latest
RUN curl -fsS https://dotenvx.sh/install.sh | sh
COPY . .
CMD ["dotenvx", "run", "--", "node", "index.js"]docker run -it --rm -v $(pwd):/app dotenv/dotenvx run -- node index.jsFROM node:latest
RUN curl -fsS https://dotenvx.sh/install.sh | sh
COPY . .
CMD ["dotenvx", "run", "--", "node", "index.js"]docker run -it --rm -v $(pwd):/app dotenv/dotenvx run -- node index.jsdotenvx set NEW_SECRET "value" -f .env.productiondotenvx set NEW_SECRET "value" -f .env.production
**Rotate a value:**
```sh
dotenvx set API_KEY "new-key-value" -f .env.productiondotenvx get -f .env.production # needs private key available
dotenvx get API_KEY -f .env.production # single valuedotenvx encrypt -f .env.production
**轮换密钥值:**
```sh
dotenvx set API_KEY "new-key-value" -f .env.productiondotenvx get -f .env.production # 需要可用的私钥
dotenvx get API_KEY -f .env.production # 查看单个值dotenvx encrypt -f .env.production
**Suppress dotenvx output in scripts:**
```sh
dotenvx run --quiet -- ./my-script.shdotenvx run -f .env.ci --strict -- npm test
**在脚本中抑制dotenvx的输出:**
```sh
dotenvx run --quiet -- ./my-script.shdotenvx run -f .env.ci --strict -- npm testdotenvx extundefineddotenvx ext genexample # 从.env生成.env.example
dotenvx ext genexample -f .env.production # 从指定文件生成
dotenvx ext gitignore # 将.env.keys追加到.gitignore
dotenvx ext ls # 列出项目中所有.env文件
dotenvx ext ls -f .env.production # 检查指定文件
dotenvx ext settings # 查看当前dotenvx设置undefinedMISSING_ENV_FILE.env--ignore=MISSING_ENV_FILEMISSING_KEY.envDOTENV_PRIVATE_KEY_*_PRODUCTION.env.productiondeno run npm:@dotenvx/dotenvx encrypt$VARSdotenvx run -- sh -c 'echo $MY_VAR'dotenvx extdotenvx ext genexample # generate .env.example from .env
dotenvx ext genexample -f .env.production # from specific file
dotenvx ext gitignore # append .env.keys to .gitignore
dotenvx ext ls # list all .env files in project
dotenvx ext ls -f .env.production # check specific file
dotenvx ext settings # view current dotenvx settings