@dotenvx/dotenvx 2.38.2 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/README.md +197 -3314
  2. package/bin/dotenvx.cjs +34 -0
  3. package/config.cjs +1 -0
  4. package/config.d.ts +1 -0
  5. package/config.mjs +2 -0
  6. package/index.cjs +141 -0
  7. package/index.d.ts +66 -0
  8. package/index.mjs +3 -0
  9. package/lib/cli.cjs +43 -0
  10. package/lib/native-package.cjs +21 -0
  11. package/lib/platforms.cjs +18 -0
  12. package/{src/lib/helpers/redactOutput.js → lib/redactOutput.cjs} +2 -48
  13. package/lib/redaction.cjs +64 -0
  14. package/lib/validateOptions.cjs +57 -0
  15. package/native.cjs +23 -0
  16. package/package.json +57 -65
  17. package/CHANGELOG.md +0 -2733
  18. package/src/cli/actions/armor/down.js +0 -38
  19. package/src/cli/actions/armor/invite.js +0 -21
  20. package/src/cli/actions/armor/move.js +0 -43
  21. package/src/cli/actions/armor/open.js +0 -28
  22. package/src/cli/actions/armor/pull.js +0 -38
  23. package/src/cli/actions/armor/push.js +0 -38
  24. package/src/cli/actions/armor/status.js +0 -7
  25. package/src/cli/actions/armor/up.js +0 -38
  26. package/src/cli/actions/check.js +0 -78
  27. package/src/cli/actions/curl.js +0 -71
  28. package/src/cli/actions/decrypt.js +0 -119
  29. package/src/cli/actions/del.js +0 -54
  30. package/src/cli/actions/doctor.js +0 -22
  31. package/src/cli/actions/encrypt.js +0 -104
  32. package/src/cli/actions/ext/genexample.js +0 -36
  33. package/src/cli/actions/ext/gitignore.js +0 -106
  34. package/src/cli/actions/ext/prebuild.js +0 -7
  35. package/src/cli/actions/ext/precommit.js +0 -38
  36. package/src/cli/actions/ext/scan.js +0 -33
  37. package/src/cli/actions/feedback.js +0 -42
  38. package/src/cli/actions/get.js +0 -128
  39. package/src/cli/actions/init.js +0 -67
  40. package/src/cli/actions/keychain/down.js +0 -30
  41. package/src/cli/actions/keychain/pull.js +0 -30
  42. package/src/cli/actions/keychain/push.js +0 -30
  43. package/src/cli/actions/keychain/up.js +0 -30
  44. package/src/cli/actions/keypair.js +0 -84
  45. package/src/cli/actions/login.js +0 -64
  46. package/src/cli/actions/logout.js +0 -37
  47. package/src/cli/actions/ls.js +0 -76
  48. package/src/cli/actions/policy.js +0 -14
  49. package/src/cli/actions/primitivesCheck.js +0 -32
  50. package/src/cli/actions/primitivesProfile.js +0 -15
  51. package/src/cli/actions/primitivesRedact.js +0 -19
  52. package/src/cli/actions/protect.js +0 -75
  53. package/src/cli/actions/protectDocker.js +0 -30
  54. package/src/cli/actions/protectProcess.js +0 -126
  55. package/src/cli/actions/protectStdin.js +0 -80
  56. package/src/cli/actions/run.js +0 -203
  57. package/src/cli/actions/set.js +0 -103
  58. package/src/cli/actions/settings/device.js +0 -23
  59. package/src/cli/actions/settings/hostname.js +0 -20
  60. package/src/cli/actions/settings/off.js +0 -14
  61. package/src/cli/actions/settings/on.js +0 -14
  62. package/src/cli/actions/settings/path.js +0 -20
  63. package/src/cli/actions/settings/token.js +0 -23
  64. package/src/cli/actions/settings/username.js +0 -20
  65. package/src/cli/actions/update.js +0 -15
  66. package/src/cli/commandAction.js +0 -16
  67. package/src/cli/commands/armor.js +0 -129
  68. package/src/cli/commands/custody.js +0 -45
  69. package/src/cli/commands/ext.js +0 -88
  70. package/src/cli/commands/fileOptions.js +0 -22
  71. package/src/cli/commands/native.js +0 -54
  72. package/src/cli/commands/primitives.js +0 -73
  73. package/src/cli/commands/settings.js +0 -63
  74. package/src/cli/dotenvx.js +0 -443
  75. package/src/cli/help.js +0 -179
  76. package/src/db/device.js +0 -67
  77. package/src/db/session.js +0 -330
  78. package/src/lib/api/getAccount.js +0 -32
  79. package/src/lib/api/getConnectionResources.js +0 -21
  80. package/src/lib/api/getTeamConnections.js +0 -27
  81. package/src/lib/api/getTeamServices.js +0 -23
  82. package/src/lib/api/getTeams.js +0 -28
  83. package/src/lib/api/postArmorDown.js +0 -48
  84. package/src/lib/api/postArmorMove.js +0 -48
  85. package/src/lib/api/postArmorPull.js +0 -48
  86. package/src/lib/api/postArmorPush.js +0 -48
  87. package/src/lib/api/postArmorUp.js +0 -53
  88. package/src/lib/api/postConnectionKeypair.js +0 -23
  89. package/src/lib/api/postFeedback.js +0 -31
  90. package/src/lib/api/postLogout.js +0 -34
  91. package/src/lib/api/postOauthDeviceCode.js +0 -38
  92. package/src/lib/api/postOauthToken.js +0 -35
  93. package/src/lib/api/postTeamInvitation.js +0 -28
  94. package/src/lib/api/teamConnectionSetup.js +0 -31
  95. package/src/lib/config.d.ts +0 -1
  96. package/src/lib/config.js +0 -1
  97. package/src/lib/conventions/environment.js +0 -27
  98. package/src/lib/conventions/filepaths.js +0 -9
  99. package/src/lib/conventions/keynames.js +0 -38
  100. package/src/lib/custodians/index.js +0 -75
  101. package/src/lib/custodians/local/bitwarden.js +0 -165
  102. package/src/lib/custodians/local/file.js +0 -18
  103. package/src/lib/custodians/local/native/backend.js +0 -56
  104. package/src/lib/custodians/local/native/index.js +0 -28
  105. package/src/lib/custodians/local/native/store.js +0 -24
  106. package/src/lib/custodians/local/onepassword.js +0 -149
  107. package/src/lib/custodians/managed/armor/index.js +0 -14
  108. package/src/lib/custodians/managed/armor/store.js +0 -48
  109. package/src/lib/custodians/resolveLocalKey.js +0 -67
  110. package/src/lib/decryptors/armor/index.js +0 -23
  111. package/src/lib/decryptors/decryptor-worker.js +0 -6
  112. package/src/lib/decryptors/index.js +0 -69
  113. package/src/lib/envfile/discovery/discoverEnvFiles.js +0 -29
  114. package/src/lib/envfile/discovery/extractEnvKeys.js +0 -173
  115. package/src/lib/envfile/discovery/scanSource.js +0 -79
  116. package/src/lib/envfile/parsing/formatEnvfileSyntaxError.js +0 -24
  117. package/src/lib/envfile/parsing/readEnvfile.js +0 -43
  118. package/src/lib/envfile/parsing/resolveEnvfilePath.js +0 -5
  119. package/src/lib/envfile/rendering/normalizeEnvfile.js +0 -53
  120. package/src/lib/envfile/rendering/previewEnvfile.js +0 -43
  121. package/src/lib/envfile/rendering/renderEnvfile.js +0 -30
  122. package/src/lib/envfile/validation/diagnosticLocation.js +0 -29
  123. package/src/lib/envfile/validation/protectEnvfile.js +0 -40
  124. package/src/lib/envfile/validation/validateEnvfile.js +0 -14
  125. package/src/lib/events/backends/armor.js +0 -31
  126. package/src/lib/events/background.js +0 -59
  127. package/src/lib/events/catalog.js +0 -14
  128. package/src/lib/events/cli.js +0 -40
  129. package/src/lib/events/delivery.js +0 -89
  130. package/src/lib/events/index.js +0 -73
  131. package/src/lib/events/metadata.js +0 -25
  132. package/src/lib/events/sdk.js +0 -44
  133. package/src/lib/events/worker.js +0 -29
  134. package/src/lib/events/workerEnvironment.js +0 -14
  135. package/src/lib/helpers/armoredKeyDisplay.js +0 -10
  136. package/src/lib/helpers/arrayToTree.js +0 -27
  137. package/src/lib/helpers/buildApiError.js +0 -19
  138. package/src/lib/helpers/buildCommandEnvs.js +0 -40
  139. package/src/lib/helpers/buildConfigEnvs.js +0 -13
  140. package/src/lib/helpers/buildEnvs.js +0 -24
  141. package/src/lib/helpers/buildOauthError.js +0 -14
  142. package/src/lib/helpers/canonicalEnvFilename.js +0 -13
  143. package/src/lib/helpers/catchAndLog.js +0 -16
  144. package/src/lib/helpers/checklist.js +0 -50
  145. package/src/lib/helpers/chomp.js +0 -5
  146. package/src/lib/helpers/colorDepth.js +0 -23
  147. package/src/lib/helpers/conventions.js +0 -28
  148. package/src/lib/helpers/createElapsedStatus.js +0 -17
  149. package/src/lib/helpers/createProtectSpinner.js +0 -13
  150. package/src/lib/helpers/createSpinner.js +0 -40
  151. package/src/lib/helpers/cryptography/decryptKeyValue.js +0 -50
  152. package/src/lib/helpers/cryptography/index.js +0 -7
  153. package/src/lib/helpers/cryptography/isDotenvPublicKey.js +0 -7
  154. package/src/lib/helpers/cryptography/isPlainKey.js +0 -7
  155. package/src/lib/helpers/cryptography/mutateKeysSrc.js +0 -22
  156. package/src/lib/helpers/cryptography/mutateSrc.js +0 -24
  157. package/src/lib/helpers/custodySelect.js +0 -25
  158. package/src/lib/helpers/decryptDeviceValue.js +0 -7
  159. package/src/lib/helpers/detectEncoding.js +0 -22
  160. package/src/lib/helpers/detectEncodingSync.js +0 -22
  161. package/src/lib/helpers/dotenvOptionPaths.js +0 -25
  162. package/src/lib/helpers/dotenvPrivateKeyNames.js +0 -7
  163. package/src/lib/helpers/enclavedHint.js +0 -11
  164. package/src/lib/helpers/encryptDeviceValue.js +0 -7
  165. package/src/lib/helpers/envResolution/determine.js +0 -49
  166. package/src/lib/helpers/envResolution/index.js +0 -8
  167. package/src/lib/helpers/errors.js +0 -374
  168. package/src/lib/helpers/escape.js +0 -6
  169. package/src/lib/helpers/execute.js +0 -12
  170. package/src/lib/helpers/executeCommand.js +0 -208
  171. package/src/lib/helpers/executeDynamic.js +0 -86
  172. package/src/lib/helpers/executeExtension.js +0 -39
  173. package/src/lib/helpers/filterKeys.js +0 -15
  174. package/src/lib/helpers/findEnvFiles.js +0 -25
  175. package/src/lib/helpers/formatCode.js +0 -11
  176. package/src/lib/helpers/fsx.js +0 -110
  177. package/src/lib/helpers/guessPrivateKeyFilename.js +0 -15
  178. package/src/lib/helpers/hasPlaintextSecrets.js +0 -7
  179. package/src/lib/helpers/http.js +0 -14
  180. package/src/lib/helpers/installPrecommitHook.js +0 -82
  181. package/src/lib/helpers/installProtectFilter.js +0 -57
  182. package/src/lib/helpers/installProtectIgnore.js +0 -27
  183. package/src/lib/helpers/isPublicKey.js +0 -3
  184. package/src/lib/helpers/isTeamRequiredError.js +0 -10
  185. package/src/lib/helpers/jsonToEnv.js +0 -7
  186. package/src/lib/helpers/keypairMetadata.js +0 -90
  187. package/src/lib/helpers/kits/sample.js +0 -5
  188. package/src/lib/helpers/linuxSecretService.js +0 -52
  189. package/src/lib/helpers/listenForOpenKey.js +0 -46
  190. package/src/lib/helpers/logProtectedFiles.js +0 -9
  191. package/src/lib/helpers/logSetSummary.js +0 -21
  192. package/src/lib/helpers/macosKeychain.js +0 -52
  193. package/src/lib/helpers/mask.js +0 -22
  194. package/src/lib/helpers/maskEnvSrc.js +0 -15
  195. package/src/lib/helpers/maskProcessedEnvs.js +0 -29
  196. package/src/lib/helpers/matchesStoredKey.js +0 -5
  197. package/src/lib/helpers/nativeStoreError.js +0 -10
  198. package/src/lib/helpers/normalizeDotenvConfigConvention.js +0 -13
  199. package/src/lib/helpers/normalizeDotenvConfigIgnore.js +0 -18
  200. package/src/lib/helpers/normalizeDotenvConfigPath.js +0 -14
  201. package/src/lib/helpers/normalizeDotenvConfigQuiet.js +0 -13
  202. package/src/lib/helpers/normalizeToken.js +0 -5
  203. package/src/lib/helpers/openUrl.js +0 -7
  204. package/src/lib/helpers/packageJson.js +0 -3
  205. package/src/lib/helpers/parseWithDecryptor.js +0 -115
  206. package/src/lib/helpers/plaintextKeys.js +0 -9
  207. package/src/lib/helpers/precommitEnvPatterns.js +0 -1
  208. package/src/lib/helpers/prependPublicKey.js +0 -17
  209. package/src/lib/helpers/preserveShebang.js +0 -16
  210. package/src/lib/helpers/prompts.js +0 -169
  211. package/src/lib/helpers/protectSettings.js +0 -64
  212. package/src/lib/helpers/ptyCommand.js +0 -27
  213. package/src/lib/helpers/readEnvKey.js +0 -32
  214. package/src/lib/helpers/redact.js +0 -9
  215. package/src/lib/helpers/redactProcessOutput.js +0 -58
  216. package/src/lib/helpers/redactedValues.js +0 -29
  217. package/src/lib/helpers/removeDynamicHelpSection.js +0 -21
  218. package/src/lib/helpers/removeEnvKey.js +0 -51
  219. package/src/lib/helpers/removeLegacyProtectFilter.js +0 -43
  220. package/src/lib/helpers/removeOptionsHelpParts.js +0 -59
  221. package/src/lib/helpers/resolveBitwardenPassword.js +0 -165
  222. package/src/lib/helpers/resolveDirectoryFilepath.js +0 -16
  223. package/src/lib/helpers/resolveEnvKeysFile.js +0 -11
  224. package/src/lib/helpers/resolveHome.js +0 -12
  225. package/src/lib/helpers/resolveOnePassword.js +0 -82
  226. package/src/lib/helpers/sanitizeCommandForMetadata.js +0 -64
  227. package/src/lib/helpers/selectConnection.js +0 -51
  228. package/src/lib/helpers/selectConnectionResource.js +0 -41
  229. package/src/lib/helpers/selectEnvfileEnvs.js +0 -29
  230. package/src/lib/helpers/selectKeyStorage.js +0 -140
  231. package/src/lib/helpers/statusReporter.js +0 -8
  232. package/src/lib/helpers/storeKeyStorage.js +0 -39
  233. package/src/lib/helpers/teamChoicesFromMeta.js +0 -8
  234. package/src/lib/helpers/truncate.js +0 -10
  235. package/src/lib/helpers/uninstallPrecommitHook.js +0 -67
  236. package/src/lib/helpers/upsertEnvKey.js +0 -62
  237. package/src/lib/helpers/windowsCredentialManager.js +0 -166
  238. package/src/lib/main.d.ts +0 -509
  239. package/src/lib/main.js +0 -468
  240. package/src/lib/providers/index.js +0 -86
  241. package/src/lib/providers/native/index.js +0 -2
  242. package/src/lib/resolvers/envs.js +0 -416
  243. package/src/lib/resolvers/get.js +0 -87
  244. package/src/lib/resolvers/keypair.js +0 -135
  245. package/src/lib/resolvers/ls.js +0 -69
  246. package/src/lib/services/armorDown.js +0 -73
  247. package/src/lib/services/armorInvite.js +0 -36
  248. package/src/lib/services/armorMove.js +0 -55
  249. package/src/lib/services/armorOpen.js +0 -26
  250. package/src/lib/services/armorPull.js +0 -73
  251. package/src/lib/services/armorPush.js +0 -66
  252. package/src/lib/services/armorUp.js +0 -71
  253. package/src/lib/services/custodyTransfer.js +0 -50
  254. package/src/lib/services/doctor.js +0 -93
  255. package/src/lib/services/genexample.js +0 -112
  256. package/src/lib/services/init.js +0 -83
  257. package/src/lib/services/keychainDown.js +0 -60
  258. package/src/lib/services/keychainPull.js +0 -46
  259. package/src/lib/services/keychainPush.js +0 -51
  260. package/src/lib/services/keychainUp.js +0 -72
  261. package/src/lib/services/login.js +0 -51
  262. package/src/lib/services/logout.js +0 -26
  263. package/src/lib/services/prebuild.js +0 -91
  264. package/src/lib/services/precommit.js +0 -144
  265. package/src/lib/services/validate.js +0 -57
  266. package/src/lib/transforms/decrypt.js +0 -98
  267. package/src/lib/transforms/del.js +0 -58
  268. package/src/lib/transforms/encrypt.js +0 -164
  269. package/src/lib/transforms/set.js +0 -144
  270. package/src/shared/colors.js +0 -67
  271. package/src/shared/logger.js +0 -148
package/README.md CHANGED
@@ -1,3390 +1,273 @@
1
- [![dotenvx](https://dotenvx.com/banner.png?v2)](https://dotenvx.com)
1
+ # dotenvx Node.js SDK — 3.0 beta prototype
2
2
 
3
- *A secure dotenv*–from the creator of [`dotenv`](https://github.com/motdotla/dotenv).
3
+ The Node.js adapter for Forge's shared Rust `dotenvx-sdk`. Parsing, expansion,
4
+ decryption, source selection, custody delegation, and Dotenvx.toml policy use
5
+ the same engine as Ruby and Python. JavaScript owns the public API, environment
6
+ updates, diagnostics, and output interception.
4
7
 
5
- * Encrypt
6
- * Commit
7
- * Ship
8
+ ## Local development
8
9
 
9
- [Install](https://dotenvx.com/docs/install) · [Quickstart](https://dotenvx.com/docs/quickstart)
10
-
11
-  
12
-
13
-
14
- ### Quickstart [![npm version](https://img.shields.io/npm/v/@dotenvx/dotenvx.svg)](https://www.npmjs.com/package/@dotenvx/dotenvx) [![downloads](https://img.shields.io/npm/dw/@dotenvx/dotenvx)](https://www.npmjs.com/package/@dotenvx/dotenvx)
15
-
16
- Install and use it in code just like `dotenv`.
17
-
18
- ```sh
19
- npm install @dotenvx/dotenvx --save
20
- ```
21
- ```js
22
- // index.js
23
- require('@dotenvx/dotenvx').config()
24
- // or import '@dotenvx/dotenvx/config' // for esm
25
-
26
- console.log(`Hello ${process.env.HELLO}`)
27
- ```
28
-
29
-  
30
-
31
- or install globally - *unlocks dotenv for any language, framework, or platform!*
32
-
33
- <details><summary>with npm 🌍</summary><br>
34
-
35
- ```sh
36
- npm i -g @dotenvx/dotenvx
37
- dotenvx encrypt
38
- ```
39
-
40
- [![npm installs](https://img.shields.io/npm/dt/@dotenvx/dotenvx)](https://npmjs.com/@dotenvx/dotenvx)
41
-
42
- &nbsp;
43
-
44
- </details>
45
- <details><summary>with curl 🌐</summary><br>
46
-
47
- ```sh
48
- curl -sfS https://dotenvx.sh | sh
49
- dotenvx encrypt
50
- ```
51
-
52
- [![curl installs](https://img.shields.io/endpoint?url=https://dotenvx.sh/stats/curl&label=curl%20installs)](https://github.com/dotenvx/dotenvx.sh/blob/main/install.sh)
53
-
54
- &nbsp;
55
-
56
- </details>
57
-
58
- <details><summary>with brew 🍺</summary><br>
59
-
60
- ```sh
61
- brew tap dotenvx/brew
62
- brew trust dotenvx/brew
63
- brew install dotenvx
64
- dotenvx encrypt
65
- ```
66
-
67
- [![brew installs](https://img.shields.io/github/downloads/dotenvx/dotenvx/total?label=brew%20installs)](https://github.com/dotenvx/homebrew-brew/blob/main/Formula/dotenvx.rb)
68
-
69
- &nbsp;
70
-
71
- </details>
72
-
73
- <details><summary>with docker 🐳</summary><br>
74
-
75
- ```sh
76
- docker run -it --rm -v $(pwd):/app dotenv/dotenvx encrypt
77
- ```
78
-
79
- [![docker pulls](https://img.shields.io/docker/pulls/dotenv/dotenvx)](https://hub.docker.com/r/dotenv/dotenvx)
80
-
81
- &nbsp;
82
-
83
- </details>
84
-
85
- <details><summary>with github releases 🐙</summary><br>
86
-
87
- ```sh
88
- curl -L -o dotenvx.tar.gz "https://github.com/dotenvx/dotenvx/releases/latest/download/dotenvx-$(uname -s)-$(uname -m).tar.gz"
89
- tar -xzf dotenvx.tar.gz
90
- ./dotenvx encrypt
91
- ```
92
-
93
- [![github releases](https://img.shields.io/github/downloads/dotenvx/dotenvx/total)](https://github.com/dotenvx/dotenvx/releases)
94
-
95
- &nbsp;
96
-
97
- </details>
98
-
99
-
100
- <details><summary>or windows 🪟</summary><br>
101
-
102
- ```sh
103
- winget install dotenvx
104
- dotenvx encrypt
105
- ```
106
-
107
- </details>
108
-
109
- &nbsp;
110
-
111
- ## Usage
112
-
113
- *Encrypt* your secrets in `.env` files. The values become ciphertext and only your private key can unlock them.
114
-
115
- ```sh
116
- $ dotenvx encrypt
117
- ◈ encrypted (.env)
118
- ```
119
-
120
- To encrypt a fresh plaintext file with a public key created elsewhere:
121
-
122
- ```sh
123
- dotenvx encrypt -f .env.production --with <public-key>
124
- ```
125
-
126
- This writes the supplied public key into the file and encrypts its values without creating or storing a private key. If every existing `DOTENV_PUBLIC_KEY*` entry matches the supplied key, it reuses that key, preserves existing ciphertext, and encrypts new plaintext values. A different public key, or an `encrypted:` value without a matching declared public key, fails with `ALREADY_ENCRYPTED` and leaves the file unchanged.
127
-
128
- *Commit* your encrypted `.env` files with your code. It's safe. Now you can securely share secrets through git.
129
-
130
- ```sh
131
- $ git add .env
132
- $ git commit -m "encrypt .env"
133
- ```
134
-
135
- *Ship* your code and secrets together. Dotenvx uses your private key to decrypt and inject your secrets just-in-time to your code.
136
-
137
- ```sh
138
- $ dotenvx run -- node index.js
139
- ⟐ injected env (2) from .env
140
- ```
141
-
142
- &nbsp;
143
-
144
- ## Design
145
-
146
- Three widely used and proven primitives make up Dotenvx's design. Git, .env, and secp256k1.
147
-
148
- We chose git because it is the best way to deliver digital goods. It is the container ship of the digital world. All code travels on its ships. Why not secrets? Why invent an inferior secrets delivery mechanism when the world class one is right there at your fingertips.
149
-
150
- We chose .env because it is the open standard for loading secrets into code. It represents environment variables, the core primitive that all secrets end up injected into at runtime of code.
151
-
152
- Lastly, we needed to choose an encryption algorithm. Encryption of the values inside the .env file would allow us to place those values with code, leveraging git's distribution advantages while still following the twelve-factor config – by separating the decryption key from the code (environment).
153
-
154
- It was important that we choose a proven, simple, asymmetric standard with small keys. We chose secp256k1, battle-tested by Bitcoin for more than seventeen years. We made cryptography an opinionated choice so developers wouldn't have to. Encryption just worked.
155
-
156
- The result is a system built entirely from primitives, developers already understand, and infrastructure they already use. Secrets can travel with code without becoming part of the code. Git distributes them, .env defines how apps consume them, and secp256k1 keeps their values unreadable. The kicker, all this works by setting a single private key on your infrastructure - no more risky async coordination of secrets, no more centralized downtime risk. Your secrets are always just there with your code, ready to be unlocked at runtime.
157
-
158
- [Read the whitepaper →](https://dotenvx.com/dotenvx.pdf?v=README)
159
-
160
- &nbsp;
161
-
162
- ## Run Anywhere
163
-
164
- ```sh
165
- $ echo "HELLO=World" > .env
166
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
167
-
168
- $ node index.js
169
- Hello undefined # without dotenvx
170
-
171
- $ dotenvx run -- node index.js
172
- Hello World # with dotenvx
173
- > :-D
174
- ```
175
-
176
- see [quickstart guides](https://dotenvx.com/docs)
177
-
178
- More examples
179
-
180
- <details><summary>Claude 🤖</summary><br>
181
-
182
- Run Claude with your real secrets while redacting them from its output.
183
-
184
- Prerequisite: install [Claude Code](https://code.claude.com/docs/en/setup) to get the `claude` command.
185
-
186
- ```sh
187
- $ curl -fsSL https://claude.ai/install.sh | bash
188
- $ claude --version
189
- ```
190
-
191
- ```sh
192
- $ echo "HELLO=World" > .env
193
-
194
- $ dotenvx spec
195
- $ dotenvx run -- claude -p 'Run `dotenvx get HELLO` and echo back just Hello VALUE' --dangerously-skip-permissions
196
- Hello [REDACTED]
197
- ```
198
-
199
- see [Claude redaction guide](https://dotenvx.com/docs/cli/run-redact-claude-print)
200
-
201
- </details>
202
- <details><summary>Codex ✨</summary><br>
203
-
204
- Run Codex with your real secrets while redacting them from its output.
205
-
206
- Prerequisite: install the [Codex CLI](https://developers.openai.com/codex/cli/) to get the `codex` command.
207
-
208
- ```sh
209
- $ npm install -g @openai/codex
210
- $ codex --version
211
- ```
212
-
213
- ```sh
214
- $ echo "HELLO=World" > .env
215
-
216
- $ dotenvx spec
217
- $ dotenvx run -- codex exec 'Run `dotenvx get HELLO` and echo back just Hello VALUE' --skip-git-repo-check
218
- Hello [REDACTED]
219
- ```
220
-
221
- see [Codex redaction guide](https://dotenvx.com/docs/cli/run-redact-codex-exec)
222
-
223
- </details>
224
- <details><summary>Cursor 🖱️</summary><br>
225
-
226
- Run Cursor with your real secrets while redacting them from its output.
227
-
228
- Prerequisite: install the separate [Cursor CLI](https://cursor.com/cli). Installing the Cursor desktop app does not necessarily install the `agent` command.
229
-
230
- ```sh
231
- $ curl https://cursor.com/install -fsS | bash
232
- $ agent --version
233
- ```
234
-
235
- ```sh
236
- $ echo "HELLO=World" > .env
237
-
238
- $ dotenvx spec
239
- $ dotenvx run -- agent -p --force 'Run `dotenvx get HELLO` and echo back just Hello VALUE' --output-format text
240
- Hello [REDACTED]
241
- ```
242
-
243
- see [Cursor redaction guide](https://dotenvx.com/docs/cursor)
244
-
245
- </details>
246
- <details><summary>1Password 🔐</summary><br>
247
-
248
- Run with secrets resolved directly from 1Password.
249
-
250
- ```sh
251
- $ echo "HELLO=op://Personal/hello/password" > .env
252
- $ dotenvx run -- sh -c 'echo Hello $HELLO'
253
- Hello World
254
- ```
255
-
256
- see [1Password guide](https://dotenvx.com/docs/1password)
257
-
258
- </details>
259
- <details><summary>Bitwarden 🛡️</summary><br>
260
-
261
- Run with secrets resolved directly from Bitwarden Password Manager.
262
-
263
- ```sh
264
- $ echo 'HELLO="bw://My Hello Login/password"' > .env
265
- $ dotenvx run -- sh -c 'echo Hello $HELLO'
266
- Hello World
267
- ```
268
-
269
- Install the [Bitwarden Password Manager CLI](https://bitwarden.com/help/cli/) before running dotenvx.
270
-
271
- </details>
272
- <details><summary>TypeScript 📘</summary><br>
273
-
274
- ```json
275
- // package.json
276
- {
277
- "type": "module",
278
- "dependencies": {
279
- "chalk": "^5.3.0"
280
- }
281
- }
282
- ```
283
-
284
- ```js
285
- // index.ts
286
- import chalk from 'chalk'
287
- console.log(chalk.blue(`Hello ${process.env.HELLO}`))
288
- ```
289
-
290
- ```sh
291
- $ npm install
292
- $ echo "HELLO=World" > .env
293
-
294
- $ dotenvx run -- npx tsx index.ts
295
- Hello World
296
- ```
297
-
298
- </details>
299
- <details><summary>Astro 🚀</summary><br>
300
-
301
- Preface Astro scripts with `dotenvx run --` and read your env values in Astro.
302
-
303
- ```json
304
- {
305
- "scripts": {
306
- "dev": "dotenvx run -- astro dev",
307
- "build": "dotenvx run -- astro build",
308
- "preview": "dotenvx run -- astro preview"
309
- }
310
- }
311
- ```
312
-
313
- ```astro
314
- export async function GET() {
315
- return new Response(
316
- JSON.stringify({
317
- HELLO: process.env.HELLO,
318
- }),
319
- {
320
- status: 200,
321
- headers: {
322
- "Content-Type": "application/json",
323
- },
324
- }
325
- );
326
- }
327
- ```
328
-
329
- see [astro guide](https://dotenvx.com/docs/astro)
330
-
331
- </details>
332
- <details><summary>Expo 🧭</summary><br>
333
-
334
- Preface Expo scripts with `dotenvx run --`.
335
-
336
- ```json
337
- {
338
- "scripts": {
339
- "start": "dotenvx run -- expo start",
340
- "reset-project": "node ./scripts/reset-project.js",
341
- "android": "dotenvx run -- expo start --android",
342
- "ios": "dotenvx run -- expo start --ios",
343
- "web": "dotenvx run -- expo start --web",
344
- "lint": "expo lint"
345
- }
346
- }
347
- ```
348
-
349
- see [expo guide](https://dotenvx.com/docs/expo)
350
-
351
- </details>
352
- <details><summary>Next.js ▲</summary><br>
353
-
354
- Install Dotenvx and `@dotenvx/next-env`.
355
-
356
- ```sh
357
- $ npm install @dotenvx/dotenvx
358
- $ npm install @dotenvx/next-env
359
- ```
360
-
361
- Override `@next/env` in your `package.json`.
362
-
363
- ```json
364
- {
365
- "overrides": {
366
- "@next/env": "npm:@dotenvx/next-env"
367
- }
368
- }
369
- ```
370
-
371
- Encrypt your `.env` file.
372
-
373
- ```sh
374
- $ npx dotenvx encrypt
375
- ◈ encrypted (.env)
376
- ```
377
-
378
- Your encrypted secrets are automatically injected and readable in Next.js.
379
-
380
- ```ts
381
- import { NextResponse } from 'next/server'
382
-
383
- export async function GET() {
384
- return NextResponse.json({
385
- HELLO: process.env.HELLO
386
- })
387
- }
388
- ```
389
-
390
- Set `DOTENV_PRIVATE_KEY` in production before deploying.
391
-
392
- </details>
393
- <details><summary>Cloudflare Workers ⛅️</summary><br>
394
-
395
- ```sh
396
- $ dotenvx encrypt -f .env.txt
397
- ```
398
-
399
- ```js
400
- // src/index.js
401
- import envSrc from '../.env.txt'
402
- import dotenvx from '@dotenvx/dotenvx'
403
-
404
- const config = dotenvx.config({ envs: [{ type: 'env', value: envSrc, privateKeyName: 'DOTENV_PRIVATE_KEY' }] })
405
- const envx = config.parsed
406
-
407
- export default {
408
- async fetch(request, env, ctx) {
409
- return new Response(`Hello ${envx.HELLO}`)
410
- }
411
- }
412
- ```
413
- ```json
414
- "scripts": {
415
- "deploy": "wrangler deploy",
416
- "dev": "wrangler dev --var $(dotenvx keypair -f .env.txt --format=colon)",
417
- "start": "wrangler dev --var $(dotenvx keypair -f .env.txt --format=colon)",
418
- }
419
- ```
420
-
421
- </details>
422
- <details><summary>Bun 🥟</summary><br>
423
-
424
- ```sh
425
- $ echo "HELLO=Test" > .env.test
426
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
427
-
428
- $ bun index.js
429
- Hello undefined
430
-
431
- $ dotenvx run -f .env.test -- bun index.js
432
- Hello Test
433
- ```
434
-
435
- </details>
436
- <details><summary>Deno 🦕</summary><br>
437
-
438
- ```sh
439
- $ echo "HELLO=World" > .env
440
- $ echo "console.log('Hello ' + Deno.env.get('HELLO'))" > index.ts
441
-
442
- $ deno run --allow-env index.ts
443
- Hello undefined
444
-
445
- $ dotenvx run -- deno run --allow-env index.ts
446
- Hello World
447
- ```
448
-
449
- > [!WARNING]
450
- > Some of you are attempting to use the npm module directly with `deno run`. Don't, because deno currently has incomplete support for these encryption ciphers.
451
- >
452
- > ```
453
- > $ deno run -A npm:@dotenvx/dotenvx encrypt
454
- > Unknown cipher
455
- > ```
456
- >
457
- > Instead, use `dotenvx` as designed, by installing the cli as a binary - via curl, brew, etc.
458
-
459
- </details>
460
- <details><summary>Python 🐍</summary><br>
461
-
462
- ```sh
463
- $ echo "HELLO=World" > .env
464
- $ echo 'import os;print("Hello " + os.getenv("HELLO", ""))' > index.py
465
-
466
- $ dotenvx run -- python3 index.py
467
- Hello World
468
- ```
469
-
470
- see [extended python guide](https://dotenvx.com/docs/python)
471
-
472
- </details>
473
- <details><summary>PHP 🐘</summary><br>
474
-
475
- ```sh
476
- $ echo "HELLO=World" > .env
477
- $ echo '<?php echo "Hello {$_SERVER["HELLO"]}\n";' > index.php
478
-
479
- $ dotenvx run -- php index.php
480
- Hello World
481
- ```
482
-
483
- see [extended php guide](https://dotenvx.com/docs/php)
484
-
485
- </details>
486
- <details><summary>Ruby 💎</summary><br>
487
-
488
- ```sh
489
- $ echo "HELLO=World" > .env
490
- $ echo 'puts "Hello #{ENV["HELLO"]}"' > index.rb
491
-
492
- $ dotenvx run -- ruby index.rb
493
- Hello World
494
- ```
495
-
496
- see [extended ruby guide](https://dotenvx.com/docs/ruby)
497
-
498
- </details>
499
- <details><summary>Go 🐹</summary><br>
500
-
501
- ```sh
502
- $ echo "HELLO=World" > .env
503
- $ echo 'package main; import ("fmt"; "os"); func main() { fmt.Printf("Hello %s\n", os.Getenv("HELLO")) }' > main.go
504
-
505
- $ dotenvx run -- go run main.go
506
- Hello World
507
- ```
508
-
509
- see [extended go guide](https://dotenvx.com/docs/go)
510
-
511
- </details>
512
- <details><summary>Rust 🦀</summary><br>
513
-
514
- ```sh
515
- $ echo "HELLO=World" > .env
516
- $ echo 'fn main() {let hello = std::env::var("HELLO").unwrap_or("".to_string());println!("Hello {hello}");}' > src/main.rs
517
-
518
- $ dotenvx run -- cargo run
519
- Hello World
520
- ```
521
-
522
- see [extended rust guide](https://dotenvx.com/docs/rust)
523
-
524
- </details>
525
- <details><summary>Java ☕️</summary><br>
526
-
527
- ```sh
528
- $ echo "HELLO=World" > .env
529
- $ echo 'public class Index { public static void main(String[] args) { System.out.println("Hello " + System.getenv("HELLO")); } }' > index.java
530
-
531
- $ dotenvx run -- java index.java
532
- Hello World
533
- ```
534
-
535
- </details>
536
- <details><summary>Clojure 🌿</summary><br>
537
-
538
- ```sh
539
- $ echo "HELLO=World" > .env
540
- $ echo '(println "Hello" (System/getenv "HELLO"))' > index.clj
541
-
542
- $ dotenvx run -- clojure -M index.clj
543
- Hello World
544
- ```
545
-
546
- </details>
547
- <details><summary>Kotlin 📐</summary><br>
548
-
549
- ```sh
550
- $ echo "HELLO=World" > .env
551
- $ echo 'fun main() { val hello = System.getenv("HELLO") ?: ""; println("Hello $hello") }' > index.kt
552
- $ kotlinc index.kt -include-runtime -d index.jar
553
-
554
- $ dotenvx run -- java -jar index.jar
555
- Hello World
556
- ```
557
-
558
- </details>
559
- <details><summary>.NET 🔵</summary><br>
560
-
561
- ```sh
562
- $ dotnet new console -n HelloWorld -o HelloWorld
563
- $ cd HelloWorld
564
- $ echo "HELLO=World" | Out-File -FilePath .env -Encoding utf8
565
- $ echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs
566
-
567
- $ dotenvx run -- dotnet run
568
- Hello World
569
- ```
570
-
571
- </details>
572
- <details><summary>Bash 🖥️</summary><br>
573
-
574
- ```sh
575
- $ echo "HELLO=World" > .env
576
-
577
- $ dotenvx run --quiet -- sh -c 'echo Hello $HELLO'
578
- Hello World
579
- ```
580
-
581
- </details>
582
- <details><summary>Frameworks ▲</summary><br>
583
-
584
- ```sh
585
- $ dotenvx run -- next dev
586
- $ dotenvx run -- npm start
587
- $ dotenvx run -- bin/rails s
588
- $ dotenvx run -- php artisan serve
589
- ```
590
-
591
- see [framework guides](https://dotenvx.com/docs/quickstarts)
592
-
593
- </details>
594
- <details><summary>Docker 🐳</summary><br>
595
-
596
- ```sh
597
- $ docker run -it --rm -v $(pwd):/app dotenv/dotenvx run -- node index.js
598
- ```
599
-
600
- Or in any image:
601
-
602
- ```Containerfile
603
- FROM node:latest
604
- RUN echo "HELLO=World" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js
605
- RUN curl -fsS https://dotenvx.sh/install.sh | sh
606
- CMD ["/usr/local/bin/dotenvx", "run", "--", "echo", "Hello $HELLO"]
607
- ```
608
-
609
- see [docker guide](https://dotenvx.com/docs/docker)
610
-
611
- </details>
612
- <details><summary>CI/CDs 🐙</summary><br>
613
-
614
- ```yaml
615
- name: build
616
- on: [push]
617
- jobs:
618
- build:
619
- runs-on: ubuntu-latest
620
- steps:
621
- - uses: actions/checkout@v3
622
- - uses: actions/setup-node@v3
623
- with:
624
- node-version: 16
625
- - run: curl -fsS https://dotenvx.sh/install.sh | sh
626
- - run: dotenvx run -- node build.js
627
- env:
628
- DOTENV_KEY: ${{ secrets.DOTENV_KEY }}
629
- ```
630
-
631
- see [github actions guide](https://dotenvx.com/docs/github-actions)
632
-
633
- </details>
634
- <details><summary>Platforms</summary><br>
635
-
636
- ```sh
637
- # heroku
638
- heroku buildpacks:add https://github.com/dotenvx/heroku-buildpack-dotenvx
639
-
640
- # docker
641
- RUN curl -fsS https://dotenvx.sh | sh
642
-
643
- # vercel
644
- npm install @dotenvx/dotenvx --save
645
- ```
646
-
647
- see [platform guides](https://dotenvx.com/docs/platforms)
648
-
649
- </details>
650
- <details><summary>Process Managers</summary><br>
651
-
652
- ```js
653
- // pm2
654
- "scripts": {
655
- "start": "dotenvx run -- pm2-runtime start ecosystem.config.js --env production"
656
- },
657
- ```
658
-
659
- see [process manager guides](https://dotenvx.com/docs/process-managers/pm2)
660
-
661
- </details>
662
- <details><summary>npx</summary><br>
663
-
664
- ```sh
665
- # alternatively use npx
666
- $ npx @dotenvx/dotenvx run -- node index.js
667
- $ npx @dotenvx/dotenvx run -- next dev
668
- $ npx @dotenvx/dotenvx run -- npm start
669
- ```
670
-
671
- </details>
672
- <details><summary>npm</summary><br>
673
-
674
- ```sh
675
- $ npm install @dotenvx/dotenvx --save
676
- ```
677
-
678
- ```json
679
- {
680
- "scripts": {
681
- "start": "./node_modules/.bin/dotenvx run -- node index.js"
682
- },
683
- "dependencies": {
684
- "@dotenvx/dotenvx": "^0.5.0"
685
- }
686
- }
687
- ```
688
-
689
- ```sh
690
- $ npm run start
691
-
692
- > start
693
- > ./node_modules/.bin/dotenvx run -- node index.js
694
-
695
- [dotenvx@1.X.X] injecting env (1) from .env.production
696
- Hello World
697
- ```
698
-
699
- </details>
700
- <details><summary>Variable Expansion</summary><br>
701
-
702
- Reference and expand variables already on your machine for use in your .env file.
703
-
704
- ```ini
705
- # .env
706
- USERNAME="username"
707
- DATABASE_URL="postgres://${USERNAME}@localhost/my_database"
708
- ```
709
- ```js
710
- // index.js
711
- console.log('DATABASE_URL', process.env.DATABASE_URL)
712
- ```
713
- ```sh
714
- $ dotenvx run --debug -- node index.js
715
- [dotenvx@0.14.1] injecting env (2) from .env
716
- DATABASE_URL postgres://username@localhost/my_database
717
- ```
718
-
719
- </details>
720
- <details><summary>Command Substitution</summary><br>
721
-
722
- Add the output of a command to one of your variables in your .env file.
723
-
724
- ```ini
725
- # .env
726
- DATABASE_URL="postgres://$(whoami)@localhost/my_database"
727
- ```
728
- ```js
729
- // index.js
730
- console.log('DATABASE_URL', process.env.DATABASE_URL)
731
- ```
732
- ```sh
733
- $ dotenvx run --debug -- node index.js
734
- [dotenvx@0.14.1] injecting env (1) from .env
735
- DATABASE_URL postgres://yourusername@localhost/my_database
736
- ```
737
-
738
- </details>
739
-
740
-
741
- &nbsp;
742
-
743
- ## Multiple Environments
744
-
745
- > Create a `.env.production` file and use `-f` to load it. It's straightforward, yet flexible.
746
- ```sh
747
- $ echo "HELLO=production" > .env.production
748
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
749
-
750
- $ dotenvx run -f .env.production -- node index.js
751
- [dotenvx@1.X.X] injecting env (1) from .env.production
752
- Hello production
753
- > ^^
754
- ```
755
-
756
- More examples
757
-
758
- <details><summary>multiple `.env` files</summary><br>
759
-
760
- ```sh
761
- $ echo "HELLO=local" > .env.local
762
-
763
- $ echo "HELLO=World" > .env
764
-
765
- $ dotenvx run -f .env.local,.env -- node index.js
766
- [dotenvx@1.X.X] injecting env (1) from .env.local,.env
767
- Hello local
768
- ```
769
-
770
- Comma-separate multiple files after a single `-f`. Subsequent files do NOT override pre-existing variables defined in previous files or env. This follows historic principle. For example, above `local` wins – from the first file.
771
-
772
- </details>
773
-
774
- <details><summary>`--overload` flag</summary><br>
775
-
776
- ```sh
777
- $ echo "HELLO=local" > .env.local
778
-
779
- $ echo "HELLO=World" > .env
780
-
781
- $ dotenvx run -f .env.local,.env --overload -- node index.js
782
- [dotenvx@1.X.X] injecting env (1) from .env.local,.env
783
- Hello World
784
- ```
785
-
786
- Note that with `--overload` subsequent files DO override pre-existing variables defined in previous files.
787
- </details>
788
- <details><summary>`--verbose` flag</summary><br>
789
-
790
- ```sh
791
- $ echo "HELLO=production" > .env.production
792
-
793
- $ dotenvx run -f .env.production --verbose -- node index.js
794
- [dotenvx][verbose] injecting env from /path/to/.env.production
795
- [dotenvx][verbose] HELLO set
796
- [dotenvx@1.X.X] injecting env (1) from .env.production
797
- Hello production
798
- ```
799
-
800
- </details>
801
- <details><summary>`--debug` flag</summary><br>
802
-
803
- ```sh
804
- $ echo "HELLO=production" > .env.production
805
-
806
- $ dotenvx run -f .env.production --debug -- node index.js
807
- [dotenvx][debug] configuring options
808
- [dotenvx][debug] {"envFile":[".env.production"]}
809
- [dotenvx][verbose] injecting env from /path/to/.env.production
810
- [dotenvx][debug] reading env from /path/to/.env.production
811
- [dotenvx][debug] parsing env from /path/to/.env.production
812
- [dotenvx][debug] {"HELLO":"production"}
813
- [dotenvx][debug] writing env from /path/to/.env.production
814
- [dotenvx][verbose] HELLO set
815
- [dotenvx][debug] HELLO set to production
816
- [dotenvx@1.X.X] injecting env (1) from .env.production
817
- Hello production
818
- ```
819
-
820
- </details>
821
- <details><summary>`--quiet` flag</summary><br>
822
-
823
- Use `--quiet` to suppress all output (except errors).
824
-
825
- ```sh
826
- $ echo "HELLO=production" > .env.production
827
-
828
- $ dotenvx run -f .env.production --quiet -- node index.js
829
- Hello production
830
- ```
831
-
832
- You can also set `DOTENV_QUIET=true`.
833
-
834
- ```sh
835
- $ DOTENV_QUIET=true dotenvx run -f .env.production -- node index.js
836
- Hello production
837
- ```
838
-
839
- </details>
840
- <details><summary>`--log-level` flag</summary><br>
841
-
842
- Set `--log-level` to whatever you wish. For example, to suppress warnings (risky), set log level to `error`:
843
-
844
- ```sh
845
- $ echo "HELLO=production" > .env.production
846
-
847
- $ dotenvx run -f .env.production --log-level=error -- node index.js
848
- Hello production
849
- ```
850
-
851
- Available log levels are `error, warn, info, verbose, debug, silly`
852
-
853
- </details>
854
- <details><summary>`--convention` flag</summary><br>
855
-
856
- Load envs using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order) or [dotenv-flow convention](https://www.npmjs.com/package/dotenv-flow). Set `--convention` to `nextjs` or `flow`:
857
-
858
- ```sh
859
- $ echo "HELLO=development local" > .env.development.local
860
- $ echo "HELLO=local" > .env.local
861
- $ echo "HELLO=development" > .env.development
862
- $ echo "HELLO=env" > .env
863
-
864
- $ dotenvx run --convention=nextjs -- node index.js
865
- Hello development local
866
-
867
- $ dotenvx run --convention=flow -- node index.js
868
- Hello development local
869
- ```
870
-
871
- (more conventions available upon request)
872
-
873
- </details>
874
-
875
- &nbsp;
876
-
877
- ## Encryption
878
-
879
- > Add encryption to your `.env` files with a single command. Use `dotenvx encrypt`.
880
-
881
- ```sh
882
- $ dotenvx encrypt
883
- ◈ encrypted (.env)
884
- ```
885
-
886
- [![encrypted .env](https://github.com/user-attachments/assets/46dfe1a7-a027-4d80-9207-789eccc325dc)](https://dotenvx.com)
887
-
888
- > A `DOTENV_PUBLIC_KEY` (encryption key) and a `DOTENV_PRIVATE_KEY` (decryption key) are generated using the same public-key cryptography as [Bitcoin](https://en.bitcoin.it/wiki/Secp256k1).
889
-
890
- More examples
891
-
892
- <details><summary>`.env`</summary><br>
893
-
894
- ```sh
895
- $ echo "HELLO=World" > .env
896
- $ dotenvx encrypt
897
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
898
-
899
- $ dotenvx run -- node index.js
900
- [dotenvx@1.X.X] injecting env (2) from .env
901
- Hello World
902
- ```
903
-
904
- </details>
905
- <details><summary>`.env.production`</summary><br>
906
-
907
- ```sh
908
- $ echo "HELLO=Production" > .env.production
909
- $ dotenvx encrypt -f .env.production
910
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
911
-
912
- $ DOTENV_PRIVATE_KEY_PRODUCTION="<.env.production private key>" dotenvx run -- node index.js
913
- [dotenvx@1.X.X] injecting env (2) from .env.production
914
- Hello Production
915
- ```
916
-
917
- Note the `DOTENV_PRIVATE_KEY_PRODUCTION` ends with `_PRODUCTION`. This instructs `dotenvx run` to load the `.env.production` file.
918
-
919
- </details>
920
- <details><summary>`.env.ci`</summary><br>
921
-
922
- ```sh
923
- $ echo "HELLO=Ci" > .env.ci
924
- $ dotenvx encrypt -f .env.ci
925
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
926
-
927
- $ DOTENV_PRIVATE_KEY_CI="<.env.ci private key>" dotenvx run -- node index.js
928
- [dotenvx@1.X.X] injecting env (2) from .env.ci
929
- Hello Ci
930
- ```
931
-
932
- Note the `DOTENV_PRIVATE_KEY_CI` ends with `_CI`. This instructs `dotenvx run` to load the `.env.ci` file. See the pattern?
933
-
934
- </details>
935
- <details><summary>combine multiple encrypted .env files</summary><br>
936
-
937
- ```sh
938
- $ dotenvx set HELLO World -f .env
939
- $ dotenvx set HELLO Production -f .env.production
940
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
941
-
942
- $ DOTENV_PRIVATE_KEY="<.env private key>" DOTENV_PRIVATE_KEY_PRODUCTION="<.env.production private key>" dotenvx run -- node index.js
943
- [dotenvx@1.X.X] injecting env (3) from .env, .env.production
944
- Hello World
945
- ```
946
-
947
- Note the `DOTENV_PRIVATE_KEY` instructs `dotenvx run` to load the `.env` file and the `DOTENV_PRIVATE_KEY_PRODUCTION` instructs it to load the `.env.production` file. See the pattern?
948
-
949
- </details>
950
- <details><summary>use directories with monorepos</summary><br>
951
-
952
- Point `-f` at a directory to load the `.env` inside it. From a workspace, this makes a shared root `.env` available without repeating its filename.
953
-
954
- ```text
955
- my-monorepo/
956
- .env
957
- apps/
958
- web/
959
- index.js
960
- ```
961
-
962
- ```sh
963
- $ dotenvx encrypt
964
- $ cd apps/web
965
-
966
- $ dotenvx get HELLO -f ../..
967
- World
968
-
969
- $ dotenvx run -f ../.. -- node index.js
970
- [dotenvx@1.X.X] injecting env (1) from ../../.env
971
- Hello World
972
- ```
973
-
974
- With the private key in your OS secret store, dotenvx finds it automatically from any workspace on the same machine.
975
-
976
- The directory also becomes the base when using a convention:
977
-
978
- ```sh
979
- $ dotenvx run -f ../.. --convention=nextjs -- node index.js
980
- [dotenvx@1.X.X] injecting env (1) from ../../.env.development.local, ../../.env.local, ../../.env.development, ../../.env
981
- Hello development local
982
- ```
983
-
984
- For a workspace with its own encrypted `.env`, run from that workspace:
985
-
986
- ```sh
987
- $ dotenvx run -- node index.js
988
- ```
989
-
990
- </details>
991
- <details><summary>`--stdout`</summary><br>
992
-
993
- ```sh
994
- $ echo "HELLO=World" > .env
995
- $ dotenvx encrypt --stdout
996
- $ dotenvx encrypt --stdout > .env.encrypted
997
- ```
998
-
999
- </details>
1000
-
1001
- <details><summary>other curves</summary><br>
1002
-
1003
- > `secp256k1` is a well-known and battle tested curve, in use with Bitcoin and other cryptocurrencies, but we are open to adding support for more curves.
1004
- >
1005
- > If your organization's compliance department requires [NIST approved curves](https://csrc.nist.gov/projects/elliptic-curve-cryptography) or other curves like `curve25519`, please reach out at [security@dotenvx.com](mailto:security@dotenvx.com).
1006
-
1007
- </details>
1008
- &nbsp;
1009
-
1010
- ## Advanced
1011
-
1012
- > Become a `dotenvx` power user.
1013
- >
1014
-
1015
- ### CLI 📟
1016
-
1017
- Advanced CLI commands.
1018
-
1019
- <details><summary>`run` - Variable Expansion</summary><br>
1020
-
1021
- Reference and expand variables already on your machine for use in your .env file.
1022
-
1023
- ```ini
1024
- # .env
1025
- USERNAME="username"
1026
- DATABASE_URL="postgres://${USERNAME}@localhost/my_database"
1027
- ```
1028
- ```js
1029
- // index.js
1030
- console.log('DATABASE_URL', process.env.DATABASE_URL)
1031
- ```
1032
- ```sh
1033
- $ dotenvx run --debug -- node index.js
1034
- [dotenvx@1.X.X] injecting env (2) from .env
1035
- DATABASE_URL postgres://username@localhost/my_database
1036
- ```
1037
-
1038
- </details>
1039
- <details><summary>`run` - Default Values</summary><br>
1040
-
1041
- Use default values when environment variables are unset or empty.
1042
-
1043
- ```ini
1044
- # .env
1045
- # Default value syntax: use value if set, otherwise use default
1046
- DATABASE_HOST=${DB_HOST:-localhost}
1047
- DATABASE_PORT=${DB_PORT:-5432}
1048
-
1049
- # Alternative syntax (no colon): use value if set, otherwise use default
1050
- API_URL=${API_BASE_URL-https://api.example.com}
1051
- ```
1052
- ```js
1053
- // index.js
1054
- console.log('DATABASE_HOST', process.env.DATABASE_HOST)
1055
- console.log('DATABASE_PORT', process.env.DATABASE_PORT)
1056
- console.log('API_URL', process.env.API_URL)
1057
- ```
1058
- ```sh
1059
- $ dotenvx run --debug -- node index.js
1060
- [dotenvx@1.X.X] injecting env (3) from .env
1061
- DATABASE_HOST localhost
1062
- DATABASE_PORT 5432
1063
- API_URL https://api.example.com
1064
- ```
1065
-
1066
- </details>
1067
- <details><summary>`run` - Alternate Values</summary><br>
1068
-
1069
- Use alternate values when environment variables are set and non-empty.
1070
-
1071
- ```ini
1072
- # .env
1073
- NODE_ENV=production
1074
-
1075
- # Alternate value syntax: use alternate if set and non-empty, otherwise empty
1076
- DEBUG_MODE=${NODE_ENV:+false}
1077
- LOG_LEVEL=${NODE_ENV:+error}
1078
-
1079
- # Alternative syntax (no colon): use alternate if set, otherwise empty
1080
- CACHE_ENABLED=${NODE_ENV+true}
1081
- ```
1082
- ```js
1083
- // index.js
1084
- console.log('NODE_ENV', process.env.NODE_ENV)
1085
- console.log('DEBUG_MODE', process.env.DEBUG_MODE)
1086
- console.log('LOG_LEVEL', process.env.LOG_LEVEL)
1087
- console.log('CACHE_ENABLED', process.env.CACHE_ENABLED)
1088
- ```
1089
- ```sh
1090
- $ dotenvx run --debug -- node index.js
1091
- [dotenvx@1.X.X] injecting env (4) from .env
1092
- NODE_ENV production
1093
- DEBUG_MODE false
1094
- LOG_LEVEL error
1095
- CACHE_ENABLED true
1096
- ```
1097
-
1098
- </details>
1099
- <details><summary>`run` - Interpolation Syntax Summary (Variable Expansion, Default/Alternate Values)</summary><br>
1100
-
1101
- Complete reference for variable interpolation patterns supported by dotenvx:
1102
-
1103
- ```ini
1104
- # .env
1105
- DEFINED_VAR=hello
1106
- EMPTY_VAR=
1107
- # UNDEFINED_VAR is not set
1108
-
1109
- # Default value syntax - use variable if set/non-empty, otherwise use default
1110
- TEST1=${DEFINED_VAR:-fallback} # Result: "hello"
1111
- TEST2=${EMPTY_VAR:-fallback} # Result: "fallback"
1112
- TEST3=${UNDEFINED_VAR:-fallback} # Result: "fallback"
1113
-
1114
- # Default value syntax (no colon) - use variable if set, otherwise use default
1115
- TEST4=${DEFINED_VAR-fallback} # Result: "hello"
1116
- TEST5=${EMPTY_VAR-fallback} # Result: "" (empty, but set)
1117
- TEST6=${UNDEFINED_VAR-fallback} # Result: "fallback"
1118
-
1119
- # Alternate value syntax - use alternate if variable is set/non-empty, otherwise empty
1120
- TEST7=${DEFINED_VAR:+alternate} # Result: "alternate"
1121
- TEST8=${EMPTY_VAR:+alternate} # Result: "" (empty)
1122
- TEST9=${UNDEFINED_VAR:+alternate} # Result: "" (empty)
1123
-
1124
- # Alternate value syntax (no colon) - use alternate if variable is set, otherwise empty
1125
- TEST10=${DEFINED_VAR+alternate} # Result: "alternate"
1126
- TEST11=${EMPTY_VAR+alternate} # Result: "alternate" (empty but set)
1127
- TEST12=${UNDEFINED_VAR+alternate} # Result: "" (empty)
1128
- ```
1129
-
1130
- **Key differences:**
1131
- - `:-` vs `-`: The colon makes empty values trigger the fallback
1132
- - `:+` vs `+`: The colon makes empty values not trigger the alternate
1133
- - Default syntax (`-`): Use variable value or fallback
1134
- - Alternate syntax (`+`): Use alternate value or empty string
1135
-
1136
- </details>
1137
- <details><summary>`run` - Command Substitution</summary><br>
1138
-
1139
- Add the output of a command to one of your variables in your .env file.
1140
-
1141
- ```ini
1142
- # .env
1143
- DATABASE_URL="postgres://$(whoami)@localhost/my_database"
1144
- ```
1145
- ```js
1146
- // index.js
1147
- console.log('DATABASE_URL', process.env.DATABASE_URL)
1148
- ```
1149
- ```sh
1150
- $ dotenvx run --debug -- node index.js
1151
- [dotenvx@1.X.X] injecting env (1) from .env
1152
- DATABASE_URL postgres://yourusername@localhost/my_database
1153
- ```
1154
-
1155
- </details>
1156
- <details><summary>`run` - Shell Expansion</summary><br>
1157
-
1158
- Prevent your shell from expanding inline `$VARIABLES` before dotenvx has a chance to inject it. Use a subshell.
1159
-
1160
- ```sh
1161
- $ dotenvx run --env="HELLO=World" -- sh -c 'echo Hello $HELLO'
1162
- Hello World
1163
- ```
1164
-
1165
- </details>
1166
- <details><summary>`run` - Multiline</summary><br>
1167
-
1168
- Dotenvx supports multiline values. This is particularly useful in conjunction with Docker - which [does not support multiline values](https://stackoverflow.com/questions/50299617/set-multiline-environment-variable-with-dockerfile/79578348#79578348).
1169
-
1170
- ```ini
1171
- # .env
1172
- MULTILINE_PEM="-----BEGIN PUBLIC KEY-----
1173
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNl1tL3QjKp3DZWM0T3u
1174
- LgGJQwu9WqyzHKZ6WIA5T+7zPjO1L8l3S8k8YzBrfH4mqWOD1GBI8Yjq2L1ac3Y/
1175
- bTdfHN8CmQr2iDJC0C6zY8YV93oZB3x0zC/LPbRYpF8f6OqX1lZj5vo2zJZy4fI/
1176
- kKcI5jHYc8VJq+KCuRZrvn+3V+KuL9tF9v8ZgjF2PZbU+LsCy5Yqg1M8f5Jp5f6V
1177
- u4QuUoobAgMBAAE=
1178
- -----END PUBLIC KEY-----"
1179
- ```
1180
-
1181
- ```js
1182
- // index.js
1183
- console.log('MULTILINE_PEM', process.env.MULTILINE_PEM)
1184
- ```
1185
-
1186
- ```sh
1187
- $ dotenvx run -- node index.js
1188
- MULTILINE_PEM -----BEGIN PUBLIC KEY-----
1189
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNl1tL3QjKp3DZWM0T3u
1190
- LgGJQwu9WqyzHKZ6WIA5T+7zPjO1L8l3S8k8YzBrfH4mqWOD1GBI8Yjq2L1ac3Y/
1191
- bTdfHN8CmQr2iDJC0C6zY8YV93oZB3x0zC/LPbRYpF8f6OqX1lZj5vo2zJZy4fI/
1192
- kKcI5jHYc8VJq+KCuRZrvn+3V+KuL9tF9v8ZgjF2PZbU+LsCy5Yqg1M8f5Jp5f6V
1193
- u4QuUoobAgMBAAE=
1194
- -----END PUBLIC KEY-----
1195
- ```
1196
-
1197
- </details>
1198
- <details><summary>`run` - Contextual Help</summary><br>
1199
-
1200
- Unlike other dotenv libraries, dotenvx attempts to unblock you with contextual help.
1201
-
1202
- For example, when missing a custom .env file:
1203
-
1204
- ```sh
1205
- $ dotenvx run -f .env.missing -- echo $HELLO
1206
- [MISSING_ENV_FILE] missing file (/Users/scottmotte/Code/dotenvx/playground/apr-16/.env.missing). fix: [echo "HELLO=World" > .env.missing]
1207
- ```
1208
-
1209
- or when missing a KEY:
1210
-
1211
- ```sh
1212
- $ echo "HELLO=World" > .env
1213
- $ dotenvx get GOODBYE
1214
- [MISSING_KEY] missing key (GOODBYE)
1215
- ```
1216
-
1217
- </details>
1218
- <details><summary>`run` - 1Password</summary><br>
1219
-
1220
- Resolve [1Password op://](https://developer.1password.com/docs/cli/secrets-reference-syntax/) directly from your `.env` file.
1221
-
1222
- ```ini
1223
- # .env
1224
- API_KEY=op://Personal/my_api_key/password
1225
- ```
1226
-
1227
- Install the [1Password CLI](https://developer.1password.com/docs/cli/get-started/) and authenticate with `op`. Dotenvx automatically reads `op://` values through `op read` before injecting them.
1228
-
1229
- ```sh
1230
- $ dotenvx run -- node index.js
1231
- ```
1232
-
1233
- Use `--no-1password` to leave `op://` values unresolved.
1234
-
1235
- ```sh
1236
- $ dotenvx run --no-1password -- node index.js
1237
- ```
1238
-
1239
- The same flag is available for `dotenvx get` and `dotenvx check`.
1240
-
1241
- </details>
1242
- <details><summary>`run` - Bitwarden</summary><br>
1243
-
1244
- Resolve `bw://` references directly from your `.env` file through the [Bitwarden Password Manager CLI](https://bitwarden.com/help/cli/).
1245
-
1246
- ```ini
1247
- # .env
1248
- API_KEY="bw://My GitHub Account/password"
1249
- ```
1250
-
1251
- The reference format is `bw://<item>/<field>`. The item can be a human-readable Bitwarden search term or an exact item UUID. Quote the dotenv value when the item name contains spaces.
1252
-
1253
- Supported fields are:
1254
-
1255
- - `username`
1256
- - `password`
1257
- - `uri`
1258
-
1259
- When the vault is locked in an interactive terminal, dotenvx prompts for your Bitwarden master password.
1260
-
1261
- Human-readable names are convenient, but must identify a single item. If multiple items match, Bitwarden returns an error. Use the item UUID when you need an unambiguous reference.
1262
-
1263
- If Bitwarden cannot resolve a reference, dotenvx reports the error and leaves the original `bw://` value unresolved.
1264
-
1265
- Use `--no-bitwarden` to skip Bitwarden resolution intentionally.
1266
-
1267
- ```sh
1268
- $ dotenvx run --no-bitwarden -- node index.js
1269
- ```
1270
-
1271
- The same flag is available for `dotenvx get` and `dotenvx check`.
1272
-
1273
- </details>
1274
- <details><summary>`run -f <directory>`</summary><br>
1275
-
1276
- Run a command using the `.env` file in a directory. This is useful with monorepos.
1277
-
1278
- ```sh
1279
- $ dotenvx run -f ../.. -- node index.js
1280
- [dotenvx@1.X.X] injecting env (1) from ../../.env
1281
- Hello World
1282
- ```
1283
-
1284
- </details>
1285
- <details><summary>`run -f` - multiple files</summary><br>
1286
-
1287
- Compose multiple `.env` files for environment variables loading, as you need.
1288
-
1289
- ```sh
1290
- $ echo "HELLO=local" > .env.local
1291
- $ echo "HELLO=World" > .env
1292
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1293
-
1294
- $ dotenvx run -f .env.local,.env -- node index.js
1295
- [dotenvx@1.X.X] injecting env (1) from .env.local, .env
1296
- Hello local
1297
- ```
1298
-
1299
- Comma-separate multiple files after a single `-f`. Subsequent files do NOT override pre-existing variables defined in previous files or env. This follows historic principle. For example, above `local` wins – from the first file.
1300
-
1301
- </details>
1302
- <details><summary>`run --env HELLO=String`</summary><br>
1303
-
1304
- Set environment variables as a simple `KEY=value` string pair.
1305
-
1306
- ```sh
1307
- $ echo "HELLO=World" > .env
1308
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1309
-
1310
- $ dotenvx run --env HELLO=String -f .env -- node index.js
1311
- [dotenvx@1.X.X] injecting env (1) from .env, and --env flag
1312
- Hello String
1313
- ```
1314
-
1315
- </details>
1316
- <details><summary>`run with Envfile redaction`</summary><br>
1317
-
1318
- Run any command with real environment variables while automatically redacting values selected by your Envfile from stdout and stderr.
1319
-
1320
- ```sh
1321
- $ echo "SECRET=super-secret-value" > .env
1322
- $ echo "PUBLIC_VALUE=visible-value" >> .env
1323
- $ echo "console.log(process.env.SECRET, process.env.PUBLIC_VALUE)" > index.js
1324
-
1325
- $ dotenvx spec
1326
- $ dotenvx run --quiet -- node index.js
1327
- [REDACTED] visible-value
1328
- ```
1329
-
1330
- With an Envfile, all values are redacted by default. Use `redacted: false` on individual declarations to leave those values visible. `spec` generates these settings, including public-name exceptions. If an existing environment variable takes precedence, its effective value follows the same rules. Matching is exact, so transformed or derived values are not redacted.
1331
-
1332
- Without an Envfile, `dotenvx run --redact -- yourcommand` redacts loaded values except recognized public names (containing `PUBLIC` or starting with `VITE`, case-sensitive). `_PLAIN` values are redacted too. Without either an Envfile or `--redact`, output is not redacted. An Envfile always takes precedence: its rules apply automatically, even when `--redact` is passed.
1333
-
1334
- When stdin, stdout, and stderr are attached to a terminal, dotenvx preserves interactive behavior on macOS and Linux systems with `script` available. Piped and redirected commands continue to use normal stdin, stdout, and stderr streams.
1335
-
1336
- </details>
1337
- <details><summary>`run -- claude -p`</summary><br>
1338
-
1339
- Run Claude in print mode with real environment variables while redacting any values it prints.
1340
-
1341
- ```sh
1342
- $ echo "SECRET=super-secret-value" > .env
1343
-
1344
- $ dotenvx spec
1345
- $ dotenvx run --quiet -- claude -p 'Print the value of $SECRET'
1346
- [REDACTED]
1347
- ```
1348
-
1349
- </details>
1350
- <details><summary>`run -- claude`</summary><br>
1351
-
1352
- Start a fully interactive Claude session. Claude receives the real values, but any values it prints are redacted.
1353
-
1354
- ```sh
1355
- $ echo "SECRET=super-secret-value" > .env
1356
-
1357
- $ dotenvx spec
1358
- $ dotenvx run --quiet -- claude
1359
- ```
1360
-
1361
- </details>
1362
- <details><summary>`run -- codex exec`</summary><br>
1363
-
1364
- Run Codex non-interactively with real environment variables while redacting any values it prints.
1365
-
1366
- ```sh
1367
- $ echo "SECRET=super-secret-value" > .env
1368
-
1369
- $ dotenvx spec
1370
- $ dotenvx run --quiet -- codex exec 'Print the value of $SECRET'
1371
- [REDACTED]
1372
- ```
1373
-
1374
- </details>
1375
- <details><summary>`run -- codex`</summary><br>
1376
-
1377
- Start a fully interactive Codex session. Codex receives the real values, but any values it prints are redacted.
1378
-
1379
- ```sh
1380
- $ echo "SECRET=super-secret-value" > .env
1381
-
1382
- $ dotenvx spec
1383
- $ dotenvx run --quiet -- codex
1384
- ```
1385
-
1386
- </details>
1387
- <details><summary>`run --overload`</summary><br>
1388
-
1389
- Override existing env variables. These can be variables already on your machine or variables loaded as files consecutively. The last variable seen will 'win'.
1390
-
1391
- ```sh
1392
- $ echo "HELLO=local" > .env.local
1393
- $ echo "HELLO=World" > .env
1394
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1395
-
1396
- $ dotenvx run -f .env.local,.env --overload -- node index.js
1397
- [dotenvx@1.X.X] injecting env (1) from .env.local, .env
1398
- Hello World
1399
- ```
1400
-
1401
- Note that with `--overload` subsequent files DO override pre-existing variables defined in previous files.
1402
-
1403
- </details>
1404
- <details><summary>`run` - Environment Variable Precedence (Container/Cloud Deployments)</summary><br>
1405
-
1406
- When deploying applications in containers or cloud environments, you often need to override specific environment variables at runtime without modifying committed `.env` files. By default, dotenvx follows the historic dotenv principle: **environment variables already present take precedence over `.env` files**.
1407
-
1408
- ```sh
1409
- # .env.prod contains: MODEL_REGISTRY=registry.company.com/models/v1
1410
- $ echo "MODEL_REGISTRY=registry.company.com/models/v1" > .env.prod
1411
- $ echo "console.log('MODEL_REGISTRY:', process.env.MODEL_REGISTRY)" > app.js
1412
-
1413
- # Without environment variable set - uses .env.prod value
1414
- $ dotenvx run -f .env.prod -- node app.js
1415
- MODEL_REGISTRY: registry.company.com/models/v1
1416
-
1417
- # With environment variable set (e.g., via Azure Container Service) - environment variable takes precedence
1418
- $ MODEL_REGISTRY=registry.azure.com/models/v2 dotenvx run -f .env.prod -- node app.js
1419
- MODEL_REGISTRY: registry.azure.com/models/v2
1420
-
1421
- # To force .env.prod to override environment variables, use --overload
1422
- $ MODEL_REGISTRY=registry.azure.com/models/v2 dotenvx run -f .env.prod --overload -- node app.js
1423
- MODEL_REGISTRY: registry.company.com/models/v1
1424
- ```
1425
-
1426
- **For container deployments:** Set environment variables through your cloud provider's UI/configuration (Azure Container Service, AWS ECS, etc.) to override specific values from committed `.env` files without rebuilding your application.
1427
-
1428
- </details>
1429
- <details><summary>`DOTENV_PRIVATE_KEY=key run`</summary><br>
1430
-
1431
- Decrypt your encrypted `.env` by setting `DOTENV_PRIVATE_KEY` before `dotenvx run`.
1432
-
1433
- ```sh
1434
- $ touch .env
1435
- $ dotenvx set HELLO encrypted
1436
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1437
-
1438
- # check your .env.keys files for your privateKey
1439
- $ DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
1440
- [dotenvx@1.X.X] injecting env (2) from .env
1441
- Hello encrypted
1442
- ```
1443
-
1444
- </details>
1445
- <details><summary>`DOTENV_PRIVATE_KEY_PRODUCTION=key run`</summary><br>
1446
-
1447
- Decrypt your encrypted `.env.production` by setting `DOTENV_PRIVATE_KEY_PRODUCTION` before `dotenvx run`. Alternatively, this can be already set on your server or cloud provider.
1448
-
1449
- ```sh
1450
- $ touch .env.production
1451
- $ dotenvx set HELLO "production encrypted" -f .env.production
1452
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1453
-
1454
- # check .env.keys for your privateKey
1455
- $ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
1456
- [dotenvx@1.X.X] injecting env (2) from .env.production
1457
- Hello production encrypted
1458
- ```
1459
-
1460
- Note the `DOTENV_PRIVATE_KEY_PRODUCTION` ends with `_PRODUCTION`. This instructs dotenvx run to load the `.env.production` file.
1461
-
1462
- </details>
1463
- <details><summary>`DOTENV_PRIVATE_KEY_CI=key dotenvx run`</summary><br>
1464
-
1465
- Decrypt your encrypted `.env.ci` by setting `DOTENV_PRIVATE_KEY_CI` before `dotenvx run`. Alternatively, this can be already set on your server or cloud provider.
1466
-
1467
- ```sh
1468
- $ touch .env.ci
1469
- $ dotenvx set HELLO "ci encrypted" -f .env.ci
1470
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1471
-
1472
- # check .env.keys for your privateKey
1473
- $ DOTENV_PRIVATE_KEY_CI="122...0b8" dotenvx run -- node index.js
1474
- [dotenvx@1.X.X] injecting env (2) from .env.ci
1475
- Hello ci encrypted
1476
- ```
1477
-
1478
- Note the `DOTENV_PRIVATE_KEY_CI` ends with `_CI`. This instructs dotenvx run to load the `.env.ci` file. See the pattern?
1479
-
1480
- </details>
1481
- <details><summary>`DOTENV_PRIVATE_KEY=key DOTENV_PRIVATE_KEY_PRODUCTION=key run` - Combine Multiple</summary><br>
1482
-
1483
- Decrypt your encrypted `.env` and `.env.production` files by setting `DOTENV_PRIVATE_KEY` and `DOTENV_PRIVATE_KEY_PRODUCTION` before `dotenvx run`.
1484
-
1485
- ```sh
1486
- $ touch .env
1487
- $ touch .env.production
1488
- $ dotenvx set HELLO encrypted
1489
- $ dotenvx set HELLO "production encrypted" -f .env.production
1490
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1491
-
1492
- # check .env.keys for your privateKeys
1493
- $ DOTENV_PRIVATE_KEY="122...0b8" DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
1494
- [dotenvx@1.X.X] injecting env (3) from .env, .env.production
1495
- Hello encrypted
1496
-
1497
- $ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
1498
- [dotenvx@1.X.X] injecting env (3) from .env.production, .env
1499
- Hello production encrypted
1500
- ```
1501
-
1502
- Compose any encrypted files you want this way. As long as a `DOTENV_PRIVATE_KEY_${environment}` is set, the values from `.env.${environment}` will be decrypted at runtime.
1503
-
1504
- </details>
1505
- <details><summary>`run --verbose`</summary><br>
1506
-
1507
- Set log level to `verbose`. ([log levels](https://docs.npmjs.com/cli/v8/using-npm/logging#setting-log-levels))
1508
-
1509
- ```sh
1510
- $ echo "HELLO=production" > .env.production
1511
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1512
-
1513
- $ dotenvx run -f .env.production --verbose -- node index.js
1514
- loading env from .env.production (/path/to/.env.production)
1515
- HELLO set
1516
- [dotenvx@1.X.X] injecting env (1) from .env.production
1517
- Hello production
1518
- ```
1519
-
1520
- </details>
1521
- <details><summary>`run --debug`</summary><br>
1522
-
1523
- Set log level to `debug`. ([log levels](https://docs.npmjs.com/cli/v8/using-npm/logging#setting-log-levels))
1524
-
1525
- ```sh
1526
- $ echo "HELLO=production" > .env.production
1527
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1528
-
1529
- $ dotenvx run -f .env.production --debug -- node index.js
1530
- process command [node index.js]
1531
- options: {"env":[],"envFile":[".env.production"]}
1532
- loading env from .env.production (/path/to/.env.production)
1533
- {"HELLO":"production"}
1534
- HELLO set
1535
- HELLO set to production
1536
- [dotenvx@1.X.X] injecting env (1) from .env.production
1537
- executing process command [node index.js]
1538
- expanding process command to [/opt/homebrew/bin/node index.js]
1539
- Hello production
1540
- ```
1541
-
1542
- </details>
1543
- <details><summary>`run --quiet`</summary><br>
1544
-
1545
- Use `--quiet` to suppress all output (except errors). ([log levels](https://docs.npmjs.com/cli/v8/using-npm/logging#setting-log-levels))
1546
-
1547
- ```sh
1548
- $ echo "HELLO=production" > .env.production
1549
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1550
-
1551
- $ dotenvx run -f .env.production --quiet -- node index.js
1552
- Hello production
1553
- ```
1554
-
1555
- You can also set `DOTENV_QUIET=true`.
1556
-
1557
- ```sh
1558
- $ DOTENV_QUIET=true dotenvx run -f .env.production -- node index.js
1559
- Hello production
1560
- ```
1561
-
1562
- </details>
1563
- <details><summary>`run --log-level`</summary><br>
1564
-
1565
- Set `--log-level` to whatever you wish. For example, to suppress warnings (risky), set log level to `error`:
1566
-
1567
- ```sh
1568
- $ echo "HELLO=production" > .env.production
1569
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1570
-
1571
- $ dotenvx run -f .env.production --log-level=error -- node index.js
1572
- Hello production
1573
- ```
1574
-
1575
- Available log levels are `error, warn, info, verbose, debug, silly` ([source](https://docs.npmjs.com/cli/v8/using-npm/logging#setting-log-levels))
1576
-
1577
- </details>
1578
- <details><summary>`run with an Envfile`</summary><br>
1579
-
1580
- `Envfile` is like a Dockerfile for your secrets.
1581
-
1582
- When an `Envfile` is present, `run` and `check` validate the same requirements: required values, types, enums, and ranges. No validation flag is needed. `run` performs validation before starting your command.
1583
-
1584
- ```ruby
1585
- # Envfile
1586
- env "DATABASE_URL", type: "url"
1587
- env "API_KEY"
1588
- env "SENTRY_DSN", optional: true
1589
- ```
1590
-
1591
- ```sh
1592
- $ dotenvx run -- node index.js
1593
- [INVALID_ENV] DATABASE_URL is required; API_KEY is required
1594
- ```
1595
-
1596
- Envfile validation failures warn by default; `run --strict` stops before launching the command. A `strict true` setting in Envfile, at the root or in an active file block, also makes its validation failures fatal. `check` always exits with failure when validation fails. Strictness changes enforcement, not which rules are checked. Invalid Envfile syntax always stops execution.
1597
-
1598
- Envfile values default to `redacted: true`: `run` masks their values in child stdout/stderr and resolved-value debug output, while the child still receives the real values. Set `redacted: false` for values that may appear in output. This is independent of `encrypted: true`, which controls encryption in `encrypt`, `set`, and `protect`.
1599
-
1600
- The synchronous `dotenvx.config()` API also reads `Envfile` from the current working directory and validates the final resolved values using the same rules, including selected file blocks. Validation failures warn and are returned in `{ parsed, error }`; `config({ strict: true })` or an applicable Envfile `strict true` setting makes failures throw. `ignore: ['INVALID_ENV']` suppresses validation failures. Invalid Envfile syntax always throws before loading values. With an Envfile, `config()` automatically redacts subsequent writes through Node's stdout/stderr streams, including existing `console.log` and `console.error` calls. Environment values and returned values stay unchanged. Repeated calls retain earlier secrets and add newly loaded ones. An unfinished secret prefix is masked at shutdown. Direct native writes and child processes inheriting file descriptors bypass these wrappers; use `dotenvx run` to capture child output.
1601
-
1602
- ```ruby
1603
- file ".env.development" do
1604
- env "BASE_URL", type: "url", redacted: false
1605
- env "TOKEN_SECRET", encrypted: true
1606
- end
1607
- ```
1608
-
1609
- `spec` generates declarations with encryption and redaction required by default. Encryption is required by default: root and file-level `encrypted` settings are not supported. Use `encrypted: false` on individual declarations to permit plaintext. Entirely plaintext inputs generate no encryption exceptions except for keys ending in `_PLAIN`, so the next `encrypt` encrypts the remaining values. `_PLAIN` keys get `encrypted: false` only when none of their assignments contain ciphertext; code-only references do not infer this exception. For files that already contain ciphertext, `spec` preserves plaintext values with per-key exceptions. Source files are never modified.
1610
-
1611
- `spec` infers `redacted: false` for names starting with `PUBLIC`, `VITE`, `NEXT_PUBLIC`, or `NUXT_PUBLIC`, or containing `PUBLIC` anywhere (case-sensitive). This affects visibility only; public names still require encryption unless explicitly exempted. Other names, including those ending in `_PLAIN`, remain redacted.
1612
-
1613
- `dotenvx spec` always generates `Envfile` with `strict true` at the top, including with `--overwrite` or `--stdout`. Generated policies stop commands on validation failures. Existing policies that omit `strict` continue to warn.
1614
-
1615
- If an Envfile already exists, `spec` leaves it untouched and prints `○ Envfile already exists [edit or run: spec --overwrite]`. Use `spec --overwrite` to regenerate it from the selected inputs, replacing custom rules, comments, and blocks for files absent from this machine. Interactive overwrite runs show the full file-and-code checklist with the prompt `Recreate Envfile from .env files and code`. Noninteractive runs use `.env.example` and `.env`, or the file selected with `-f`. Input validation finishes before the old Envfile is replaced; cancelled selection leaves it untouched. Symlinked Envfiles cannot be overwritten.
1616
-
1617
- Use `dotenvx spec --stdout` to print the generated Envfile without writing it, or `dotenvx spec --stdout -f .env.production` to select an input file. This works even when an Envfile already exists; `--stdout` leaves it untouched even with `--overwrite`. Prompts and progress stay on stderr so stdout contains only the generated content.
1618
-
1619
- Root and file-level `redacted` settings are not supported. Use per-key `redacted: false` to permit output visibility. When selected files specify conflicting options, the first file's explicit option wins. `check` previews values with policy-driven redaction and reports issues per key.
1620
-
1621
-
1622
- </details>
1623
- <details><summary>`run with Envfile file rules`</summary><br>
1624
-
1625
- Use exact file blocks to override rules for selected files:
1626
-
1627
- ```ruby
1628
- env "HELLO"
1629
- env "PORT", type: "port"
1630
- env "STRIPE_SECRET_KEY", optional: true
1631
-
1632
- file ".env.production" do
1633
- env "STRIPE_SECRET_KEY", required: true
1634
- env "PORT", min: 1024
1635
- end
1636
- ```
1637
-
1638
- Profiles select file combinations:
1639
-
1640
- ```ruby
1641
- profile "development", files: [".env.local", ".env"]
1642
- profile "production", files: [".env.production"]
1643
- ```
1644
-
1645
- Selection order is explicit `-f`, `--profile`, `DOTENV_FILE` / `DOTENV_PATH` / `DOTENV_F`, then `DOTENV_ENV`, `APP_ENV`, `RAILS_ENV`, `RACK_ENV`, `MIX_ENV`, and `NODE_ENV`. Without a selector, the development profile is used if declared; otherwise `.env`. Explicit unknown profiles fail.
1646
-
1647
- Both `dotenvx run -f .env.production -- node index.js` and `dotenvx check -f .env.production` use the production rules. Block declarations inherit top-level options and override only the options they specify. Encryption and redaction are specified per key.
1648
-
1649
- Paths in file blocks are relative to the Envfile. They match the selected paths exactly after path normalization (`./.env.production` matches `.env.production`); they are not basename matches or globs. Directory inputs and `DOTENV_FILE` use their resolved file paths.
1650
-
1651
- When no file block matches, top-level rules apply. Selected file blocks override explicit options in file order: the first file wins. Policy selection is independent of where the final value comes from, including shell values and `--overload`. A selected missing file still activates its block. Blocks cannot be nested, and duplicate declarations within one scope or duplicate file blocks are errors.
1652
-
1653
- </details>
1654
- <details><summary>`check`</summary><br>
1655
-
1656
- Validate the final resolved environment against your Envfile, using the same loader and precedence as `run`:
1657
-
1658
- ```sh
1659
- $ dotenvx check -f .env.local -f .env
1660
- ✔ PORT=3000 # .env.local:1
1661
-
1662
- $ dotenvx check -f .env.production
1663
- ☠ PORT=bad # .env.production:4 !port
1664
- ```
1665
-
1666
- Envfile `file` blocks define policy; they do not select files to load. By default, `check` uses the same profile and file selection as `run`. Use repeated `-f` flags or `--convention` to select layers. `DOTENV_FILE` and its aliases are also supported.
1667
-
1668
- All selected sources are merged before validation. The first file wins by default, existing shell values take precedence, and `--overload` lets later sources override earlier values. Partial files can satisfy the schema together. Validation checks final values; encryption requirements are enforced separately by `encrypt`, `set`, and `protect`. Rules are combined independently, with the first explicit file option winning.
1669
-
1670
- Missing files explicitly selected with `-f` or `DOTENV_FILE` (and its aliases) fail the check. Missing optional convention layers and implicit default files are reported as `○ skipped (filename)`. `check` has no `--strict` flag. Required values must still resolve; shell or inline values can satisfy the schema without a local file. A check with no readable files, inline values, or declared shell values fails rather than reporting an empty success.
1671
-
1672
- The preview shows redacted values and per-key diagnostics on stdout, with source locations where available. Loading errors go to stderr. `--quiet` suppresses the preview. Failed checks exit with code 1.
1673
-
1674
- </details>
1675
- <details><summary>`protect with an Envfile`</summary><br>
1676
-
1677
- The Git protection filter reads `Envfile` in the same directory as the file being staged. Encryption is required by default. Keys explicitly marked `encrypted: false` may be committed as plaintext:
1678
-
1679
- ```ruby
1680
- env "BASE_URL", encrypted: false
1681
- env "TOKEN_SECRET"
1682
- ```
1683
-
1684
- This permits plaintext `BASE_URL` while requiring `TOKEN_SECRET` and undeclared keys to be encrypted. Only keys explicitly marked `encrypted: false` may remain plaintext. `redacted` only controls output visibility.
1685
-
1686
- Without an Envfile, protection keeps its existing rules, including exemptions for `.env.example`, `.env.vault`, and `.env.x`. A `_PLAIN` suffix alone does not permit plaintext through Git protection.
1687
-
1688
- Protection inspects every assignment in the incoming Git blob, including duplicates. It does not merge files, use shell overrides, or decrypt values. Empty values, public encryption keys, and `op://` / `bw://` references remain allowed. Private-key files (`.env.keys*`) and nonempty plaintext `DOTENV_PRIVATE_KEY` values remain blocked even with `encrypted: false`.
1689
-
1690
- The policy is read from the working-tree Envfile beside the staged file, even if that policy itself is unstaged. If no adjacent Envfile exists, the Git repository root is checked. Invalid or unreadable policies block staging with an error. Envfile encryption rules also apply to otherwise exempt files such as `.env.example`.
1691
-
1692
- Accepted blobs pass through byte-for-byte. This integration applies to Git protection, not `protect --docker`.
1693
-
1694
- </details>
1695
- <details><summary>`run --strict`</summary><br>
1696
-
1697
- Exit with code `1` if any errors are encountered - like a missing .env file or decryption failure.
1698
-
1699
- ```sh
1700
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1701
-
1702
- $ dotenvx run -f .env.missing --strict -- node index.js
1703
- [MISSING_ENV_FILE] missing file (/path/to/.env.missing). fix: [echo "HELLO=World" > .env.missing]
1704
- ```
1705
-
1706
- This can be useful in `ci` scripts where you want to fail the ci if your `.env` file could not be decrypted at runtime.
1707
-
1708
- </details>
1709
- <details><summary>`run --ignore`</summary><br>
1710
-
1711
- Ignore errors like `MISSING_ENV_FILE`.
1712
-
1713
- ```sh
1714
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1715
-
1716
- $ dotenvx run -f .env.missing --ignore=MISSING_ENV_FILE -- node index.js
1717
- ...
1718
- ```
1719
-
1720
- You can also set `DOTENV_IGNORE="MISSING_ENV_FILE"`. It is parsed as a comma-separated list.
1721
-
1722
- ```sh
1723
- $ DOTENV_IGNORE="MISSING_ENV_FILE,OTHER_ERROR_CODE" dotenvx run -f .env.missing -- node index.js
1724
- ```
1725
- </details>
1726
- <details><summary>`run --convention=nextjs`</summary><br>
1727
-
1728
- Load envs using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
1729
-
1730
- ```sh
1731
- $ echo "HELLO=development local" > .env.development.local
1732
- $ echo "HELLO=local" > .env.local
1733
- $ echo "HELLO=development" > .env.development
1734
- $ echo "HELLO=env" > .env
1735
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1736
-
1737
- $ dotenvx run --convention=nextjs -- node index.js
1738
- [dotenvx@1.X.X] injecting env (1) from .env.development.local, .env.local, .env.development, .env
1739
- Hello development local
1740
- ```
1741
-
1742
- You can also set `DOTENV_CONVENTION=nextjs`.
1743
-
1744
- ```sh
1745
- $ DOTENV_CONVENTION=nextjs dotenvx run -- node index.js
1746
- [dotenvx@1.X.X] injecting env (1) from .env.development.local, .env.local, .env.development, .env
1747
- Hello development local
1748
- ```
1749
-
1750
- (more conventions available upon request)
1751
-
1752
- </details>
1753
- <details><summary>`run -f <directory> --convention=nextjs`</summary><br>
1754
-
1755
- Run a command using Next.js' convention from a directory. This is useful with monorepos.
1756
-
1757
- ```sh
1758
- $ dotenvx run -f ../.. --convention=nextjs -- node index.js
1759
- [dotenvx@1.X.X] injecting env (1) from ../../.env.development.local, ../../.env.local, ../../.env.development, ../../.env
1760
- Hello development local
1761
- ```
1762
-
1763
- </details>
1764
- <details><summary>`run --convention=flow`</summary><br>
1765
-
1766
- Load envs using [dotenv-flow's convention](https://www.npmjs.com/package/dotenv-flow). Set `--convention` to `flow`:
1767
-
1768
- ```sh
1769
- $ echo "HELLO=development local" > .env.development.local
1770
- $ echo "HELLO=development" > .env.development
1771
- $ echo "HELLO=local" > .env.local
1772
- $ echo "HELLO=env" > .env
1773
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1774
-
1775
- $ NODE_ENV=development dotenvx run --convention=flow -- node index.js
1776
- [dotenvx@1.X.X] injecting env (1) from .env.development.local, .env.development, .env.local, .env
1777
- Hello development local
1778
- ```
1779
-
1780
- You can also set `DOTENV_CONVENTION=flow`.
1781
-
1782
- ```sh
1783
- $ NODE_ENV=development DOTENV_CONVENTION=flow dotenvx run -- node index.js
1784
- [dotenvx@1.X.X] injecting env (1) from .env.development.local, .env.development, .env.local, .env
1785
- Hello development local
1786
- ```
1787
-
1788
- Further, we recommend using `DOTENV_ENV` over `NODE_ENV`– as `dotenvx` works everywhere, not just node.
1789
-
1790
- ```sh
1791
- $ DOTENV_ENV=development dotenvx run --convention=flow -- node index.js
1792
- [dotenvx@1.X.X] injecting env (1) from .env.development.local, .env.development, .env.local, .env
1793
- Hello development local
1794
- ```
1795
-
1796
- </details>
1797
- <details><summary>`run -fk`</summary><br>
1798
-
1799
- Specify a custom private-key file when using file storage.
1800
-
1801
- ```sh
1802
- $ mkdir -p apps/app1
1803
- $ touch apps/app1/.env
1804
- $ dotenvx set HELLO World -fk .env.keys -f apps/app1/.env
1805
-
1806
- $ dotenvx run -fk .env.keys -f apps/app1/.env -- yourcommand
1807
- ```
1808
-
1809
- </details>
1810
- <details><summary>`run --mask`</summary><br>
1811
-
1812
- Inject masked values into the command. By default, up to the first six characters are visible.
1813
-
1814
- ```sh
1815
- $ echo "SECRET=abcdefghijkl" > .env
1816
- $ echo "console.log(process.env.SECRET)" > index.js
1817
-
1818
- $ dotenvx run --mask --quiet -- node index.js
1819
- abcdef******
1820
- ```
1821
-
1822
- Pass a number to control how many characters are visible, such as `--mask 0` to fully mask values.
1823
-
1824
- </details>
1825
- <details><summary>`run --token`</summary><br>
1826
-
1827
- Set Armor ⛨ token for retrieving armored private keys.
1828
-
1829
- ```sh
1830
- $ dotenvx run --token "$DOTENVX_ARMOR_TOKEN" -- yourcommand
1831
- ```
1832
-
1833
- </details>
1834
- <details><summary>`run --no-native`</summary><br>
1835
-
1836
- Turn off OS secret store lookups.
1837
-
1838
- ```sh
1839
- $ dotenvx run --no-native -- yourcommand
1840
- ```
1841
-
1842
- </details>
1843
- <details><summary>`run --no-armor`</summary><br>
1844
-
1845
- Turn off [Dotenvx Armor ⛨](https://dotenvx.com/armor) features.
1846
-
1847
- ```sh
1848
- $ dotenvx run --no-armor -- yourcommand
1849
- ```
1850
-
1851
- </details>
1852
- <details><summary>`get KEY`</summary><br>
1853
-
1854
- Return a single environment variable's value.
1855
-
1856
- ```sh
1857
- $ echo "HELLO=World" > .env
1858
-
1859
- $ dotenvx get HELLO
1860
- World
1861
- ```
1862
-
1863
- </details>
1864
- <details><summary>`get KEY --mask`</summary><br>
1865
-
1866
- Return a masked environment variable value. By default, up to the first six characters are visible.
1867
-
1868
- ```sh
1869
- $ echo "SECRET=abcdefghijkl" > .env
1870
-
1871
- $ dotenvx get SECRET --mask
1872
- abcdef******
1873
- ```
1874
-
1875
- Pass a number to control how many characters are visible, such as `--mask 0` to fully mask values.
1876
-
1877
- </details>
1878
- <details><summary>`get KEY --no-native`</summary><br>
1879
-
1880
- Turn off OS secret store lookups for get.
1881
-
1882
- ```sh
1883
- $ dotenvx get HELLO --no-native
1884
- ```
1885
-
1886
- </details>
1887
- <details><summary>`get KEY --no-armor`</summary><br>
1888
-
1889
- Turn off [Dotenvx Armor ⛨](https://dotenvx.com/armor) features for get.
1890
-
1891
- ```sh
1892
- $ dotenvx get HELLO --no-armor
1893
- World
1894
- ```
1895
-
1896
- </details>
1897
- <details><summary>`get KEY --ignore`</summary><br>
1898
-
1899
- Ignore specific error codes.
1900
-
1901
- ```sh
1902
- $ dotenvx get HELLO --ignore=MISSING_ENV_FILE
1903
- ```
1904
-
1905
- Ignore multiple error codes by separating them with spaces.
1906
-
1907
- ```sh
1908
- $ dotenvx get HELLO --ignore=MISSING_ENV_FILE MISSING_KEY
1909
- ```
1910
-
1911
- You can also set `DOTENV_IGNORE`. Its value is a comma-separated list.
1912
-
1913
- ```sh
1914
- $ DOTENV_IGNORE=MISSING_ENV_FILE,OTHER dotenvx get HELLO
1915
- ```
1916
-
1917
- </details>
1918
- <details><summary>`get KEY -f`</summary><br>
1919
-
1920
- Return a single environment variable's value from a specific `.env` file.
1921
-
1922
- ```sh
1923
- $ echo "HELLO=World" > .env
1924
- $ echo "HELLO=production" > .env.production
1925
-
1926
- $ dotenvx get HELLO -f .env.production
1927
- production
1928
- ```
1929
-
1930
- </details>
1931
- <details><summary>`get KEY -f <directory>`</summary><br>
1932
-
1933
- Return a single environment variable's value from the `.env` file in a directory. This is useful with monorepos.
1934
-
1935
- ```sh
1936
- $ dotenvx get HELLO -f ../..
1937
- World
1938
- ```
1939
-
1940
- </details>
1941
- <details><summary>`get KEY -fk`</summary><br>
1942
-
1943
- Specify a custom private-key file when using file storage.
1944
-
1945
- ```sh
1946
- $ mkdir -p apps/app1
1947
- $ touch apps/app1/.env
1948
- $ dotenvx set HELLO World -fk .env.keys -f apps/app1/.env
1949
-
1950
- $ dotenvx get HELLO -fk .env.keys -f apps/app1/.env
1951
- world
1952
- ```
1953
-
1954
- </details>
1955
- <details><summary>`get KEY --env`</summary><br>
1956
-
1957
- Return a single environment variable's value from a `--env` string.
1958
-
1959
- ```sh
1960
- $ dotenvx get HELLO --env HELLO=String -f .env.production
1961
- String
1962
- ```
1963
-
1964
- </details>
1965
-
1966
- <details><summary>`get KEY --overload`</summary><br>
1967
-
1968
- Return a single environment variable's value where each found value is overloaded.
1969
-
1970
- ```sh
1971
- $ echo "HELLO=World" > .env
1972
- $ echo "HELLO=production" > .env.production
1973
-
1974
- $ dotenvx get HELLO -f .env.production --env HELLO=String -f .env --overload
1975
- World
1976
- ```
1977
-
1978
- </details>
1979
- <details><summary>`get KEY --strict`</summary><br>
1980
-
1981
- Exit with code `1` if any errors are encountered - like a missing key, missing .env file, or decryption failure.
1982
-
1983
- ```sh
1984
- $ dotenvx get DOES_NOT_EXIST --strict
1985
- [MISSING_KEY] missing key (DOES_NOT_EXIST)
1986
- ```
1987
-
1988
- </details>
1989
- <details><summary>`get KEY --convention=nextjs`</summary><br>
1990
-
1991
- Return a single environment variable's value using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
1992
-
1993
- ```sh
1994
- $ echo "HELLO=development local" > .env.development.local
1995
- $ echo "HELLO=local" > .env.local
1996
- $ echo "HELLO=development" > .env.development
1997
- $ echo "HELLO=env" > .env
1998
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
1999
-
2000
- $ dotenvx get HELLO --convention=nextjs
2001
- development local
2002
- ```
2003
-
2004
- You can also set `DOTENV_CONVENTION=nextjs`.
2005
-
2006
- ```sh
2007
- $ DOTENV_CONVENTION=nextjs dotenvx get HELLO
2008
- development local
2009
- ```
2010
-
2011
- </details>
2012
- <details><summary>`get KEY -f <directory> --convention=nextjs`</summary><br>
2013
-
2014
- Return a single environment variable's value using Next.js' convention from a directory. This is useful with monorepos.
2015
-
2016
- ```sh
2017
- $ dotenvx get HELLO -f ../.. --convention=nextjs
2018
- development local
2019
- ```
2020
-
2021
- </details>
2022
- <details><summary>`get KEY --convention=flow`</summary><br>
2023
-
2024
- Return a single environment variable's value using [dotenv-flow's convention](https://www.npmjs.com/package/dotenv-flow). Set `--convention` to `flow`:
2025
-
2026
- ```sh
2027
- $ echo "HELLO=development local" > .env.development.local
2028
- $ echo "HELLO=development" > .env.development
2029
- $ echo "HELLO=local" > .env.local
2030
- $ echo "HELLO=env" > .env
2031
- $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
2032
-
2033
- $ NODE_ENV=development dotenvx get HELLO --convention=flow
2034
- development local
2035
- ```
2036
-
2037
- You can also set `DOTENV_CONVENTION=flow`.
2038
-
2039
- ```sh
2040
- $ NODE_ENV=development DOTENV_CONVENTION=flow dotenvx get HELLO
2041
- development local
2042
- ```
2043
-
2044
- Further, we recommend using `DOTENV_ENV` over `NODE_ENV`– as `dotenvx` works everywhere, not just node.
2045
-
2046
- ```sh
2047
- $ DOTENV_ENV=development dotenvx get HELLO --convention=flow
2048
- development local
2049
- ```
2050
-
2051
- </details>
2052
- <details><summary>`get` (json)</summary><br>
2053
-
2054
- Return a json response of all key/value pairs in a `.env` file.
2055
-
2056
- ```sh
2057
- $ echo "HELLO=World" > .env
2058
-
2059
- $ dotenvx get
2060
- {"HELLO":"World"}
2061
- ```
2062
-
2063
- </details>
2064
- <details><summary>`get --pretty-print`</summary><br>
2065
-
2066
- Make the JSON output more readable.
2067
-
2068
- ```sh
2069
- $ echo "HELLO=World" > .env
2070
-
2071
- $ dotenvx get --pretty-print
2072
- {
2073
- "HELLO": "World"
2074
- }
2075
- ```
2076
-
2077
- </details>
2078
- <details><summary>`get -ik`</summary><br>
2079
-
2080
- Include only matching keys by passing `--include-key`. Glob patterns are supported.
2081
-
2082
- ```sh
2083
- $ echo "HELLO=World\nHOLA=Mundo\nGOODBYE=World" > .env
2084
-
2085
- $ dotenvx get -ik "H*"
2086
- {"HELLO":"World","HOLA":"Mundo"}
2087
- ```
2088
-
2089
- </details>
2090
- <details><summary>`get -ek`</summary><br>
2091
-
2092
- Exclude matching keys by passing `--exclude-key`. Glob patterns are supported.
2093
-
2094
- ```sh
2095
- $ echo "DOTENV_PUBLIC_KEY=public\nHELLO=World" > .env
2096
-
2097
- $ dotenvx get --format=eval-export -ek "DOTENV_PUBLIC_KEY*"
2098
- export HELLO='World'
2099
- ```
2100
-
2101
- </details>
2102
- <details><summary>`get --format colon`</summary><br>
2103
-
2104
- Return a colon-formatted response of all key/value pairs in a `.env` file.
2105
-
2106
- ```sh
2107
- $ echo "HELLO=World" > .env
2108
-
2109
- $ dotenvx get --format colon
2110
- HELLO: World
2111
- ```
2112
-
2113
- </details>
2114
- <details><summary>`get --format shell`</summary><br>
2115
-
2116
- Return a shell formatted response of all key/value pairs in a `.env` file.
2117
-
2118
- ```sh
2119
- $ echo "HELLO=World" > .env
2120
- $ echo "KEY=value" >> .env
2121
-
2122
- $ dotenvx get --format shell
2123
- HELLO=World KEY=value
2124
- ```
2125
-
2126
- This can be useful when combined with `env` on the command line.
2127
-
2128
- ```
2129
- $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
2130
- $ env $(dotenvx get --format=shell) node index.js
2131
- Hello value World
2132
- ```
2133
-
2134
- or with `export`.
2135
-
2136
- ```
2137
- $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
2138
- $ export $(dotenvx get --format=shell)
2139
- $ node index.js
2140
- Hello value World
2141
- ```
2142
-
2143
- </details>
2144
- <details><summary>`get --format eval`</summary><br>
2145
-
2146
- Return an `eval`-ready shell formatted response of all key/value pairs in a `.env` file.
2147
-
2148
- ```sh
2149
- $ echo "HELLO=World" > .env
2150
- $ echo "KEY=value" >> .env
2151
-
2152
- $ dotenvx get --format eval
2153
- HELLO="World"
2154
- KEY="value"
2155
- ```
2156
-
2157
- Note that this exports newlines and quoted strings.
2158
-
2159
- This can be useful for more complex .env values (spaces, escaped characters, quotes, etc) combined with `eval` on the command line.
2160
-
2161
- ```sh
2162
- $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
2163
- $ eval $(dotenvx get --format=eval) node index.js
2164
- Hello value World
2165
- ```
2166
-
2167
- Be careful with `eval` as it allows for arbitrary execution of commands. Prefer `dotenvx run --` but in some cases `eval` is a sharp knife that is useful to have.
2168
-
2169
- </details>
2170
-
2171
- <details><summary>`get --all`</summary><br>
2172
-
2173
- Return preset machine envs as well.
2174
-
2175
- ```sh
2176
- $ echo "HELLO=World" > .env
2177
-
2178
- $ dotenvx get --all
2179
- {"PWD":"/some/file/path","USER":"username","LIBRARY_PATH":"/usr/local/lib", ..., "HELLO":"World"}
2180
- ```
2181
-
2182
- </details>
2183
- <details><summary>`get --all --pretty-print`</summary><br>
2184
-
2185
- Make the output more readable - pretty print it.
2186
-
2187
- ```sh
2188
- $ echo "HELLO=World" > .env
2189
-
2190
- $ dotenvx get --all --pretty-print
2191
- {
2192
- "PWD": "/some/filepath",
2193
- "USER": "username",
2194
- "LIBRARY_PATH": "/usr/local/lib",
2195
- ...,
2196
- "HELLO": "World"
2197
- }
2198
- ```
2199
-
2200
- </details>
2201
- <details><summary>`set KEY value`</summary><br>
2202
-
2203
- Set an encrypted key/value (on by default).
2204
-
2205
- ```sh
2206
- $ touch .env
2207
-
2208
- $ dotenvx set HELLO World
2209
- set HELLO with encryption (.env)
2210
- ```
2211
-
2212
- </details>
2213
- <details><summary>`set KEY value -f`</summary><br>
2214
-
2215
- Set an (encrypted) key/value for another `.env` file.
2216
-
2217
- ```sh
2218
- $ touch .env.production
2219
-
2220
- $ dotenvx set HELLO production -f .env.production
2221
- set HELLO with encryption (.env.production)
2222
- ```
2223
-
2224
- </details>
2225
- <details><summary>`set KEY value -fk`</summary><br>
2226
-
2227
- Specify a custom private-key file when using file storage.
2228
-
2229
- ```sh
2230
- $ mkdir -p apps/app1
2231
- $ touch apps/app1/.env
2232
-
2233
- $ dotenvx set HELLO World -fk .env.keys -f apps/app1/.env
2234
- set HELLO with encryption (.env)
2235
- ```
2236
-
2237
- Put it to use.
2238
-
2239
- ```sh
2240
- $ dotenvx get -fk .env.keys -f apps/app1/.env
2241
- ```
2242
-
2243
- Use it with a relative path.
2244
-
2245
- ```sh
2246
- $ cd apps/app1
2247
- $ dotenvx get -fk ../../.env.keys -f .env
2248
- ```
2249
-
2250
- </details>
2251
- <details><summary>`set KEY "value with spaces"`</summary><br>
2252
-
2253
- Set a value containing spaces.
2254
-
2255
- ```sh
2256
- $ touch .env.ci
2257
-
2258
- $ dotenvx set HELLO "my ci" -f .env.ci
2259
- set HELLO with encryption (.env.ci)
2260
- ```
2261
-
2262
- </details>
2263
- <details><summary>`set KEY -- "- + * ÷"`</summary><br>
2264
-
2265
- If your value starts with a dash (`-`), then place two dashes instructing the cli that there are no more flag arguments.
2266
-
2267
- ```sh
2268
- $ touch .env.ci
2269
-
2270
- $ dotenvx set HELLO -f .env.ci -- "- + * ÷"
2271
- set HELLO with encryption (.env.ci)
2272
- ```
2273
-
2274
- </details>
2275
- <details><summary>`set KEY value --plain`</summary><br>
2276
-
2277
- Set a plaintext key/value.
2278
-
2279
- ```sh
2280
- $ touch .env
2281
-
2282
- $ dotenvx set HELLO World --plain
2283
- set HELLO (.env)
2284
- ```
2285
-
2286
- </details>
2287
- <details><summary>`set KEY_PLAIN value`</summary><br>
2288
-
2289
- Set a plaintext key/value inside an encrypted `.env` file by ending the key with `_PLAIN`.
2290
-
2291
- ```sh
2292
- $ touch .env
2293
-
2294
- $ dotenvx set HELLO_PLAIN World
2295
- set HELLO_PLAIN (.env)
2296
- ```
2297
-
2298
- Without an Envfile, `dotenvx set` and `dotenvx encrypt` skip keys ending in `_PLAIN`. With an Envfile, its per-key encryption rules take precedence.
2299
-
2300
- </details>
2301
- <details><summary>`set KEY value --no-native`</summary><br>
2302
-
2303
- Turn off OS secret store lookups for set.
2304
-
2305
- ```sh
2306
- $ dotenvx set HELLO World --no-native
2307
- ```
2308
-
2309
- </details>
2310
- <details><summary>`set KEY value --no-armor`</summary><br>
2311
-
2312
- Turn off [Dotenvx Armor ⛨](https://dotenvx.com/armor) features for set.
2313
-
2314
- ```sh
2315
- $ dotenvx set HELLO World --no-armor
2316
- ◈ encrypted HELLO (.env)
2317
- ```
2318
-
2319
- </details>
2320
- <details><summary>`set KEY value --no-create`</summary><br>
2321
-
2322
- Do not create a missing `.env` file.
2323
-
2324
- ```sh
2325
- $ dotenvx set HELLO World -f .env.production --no-create
2326
- ```
2327
-
2328
- </details>
2329
- <details><summary>`del KEY`</summary><br>
2330
-
2331
- Delete a key from your `.env` file.
2332
-
2333
- ```sh
2334
- $ echo "HELLO=World" > .env
2335
-
2336
- $ dotenvx del HELLO
2337
- ◇ removed HELLO (.env)
2338
- ```
2339
-
2340
- </details>
2341
- <details><summary>`del KEY -f`</summary><br>
2342
-
2343
- Delete a key from another `.env` file.
2344
-
2345
- ```sh
2346
- $ echo "HELLO=production" > .env.production
2347
-
2348
- $ dotenvx del HELLO -f .env.production
2349
- ◇ removed HELLO (.env.production)
2350
- ```
2351
-
2352
- </details>
2353
- <details><summary>`encrypt`</summary><br>
2354
-
2355
- Encrypt the contents of a `.env` file to an encrypted `.env` file.
2356
-
2357
- When the current directory contains an Envfile, `encrypt` encrypts all keys except those explicitly marked `encrypted: false` in the applicable declarations. Values with effective `encrypted: false` remain unchanged, including any existing ciphertext. Undeclared keys require encryption too; both `run` and `check` validate loaded keys and their shell overrides without checking unrelated host environment variables. `run` warns on validation failures by default and refuses to launch when strictness is enabled; `check` exits with failure. The policy applies even with `--key` or `--stdout`; `--exclude-key` can further narrow the selection. If no values need encryption, no keypair is generated. Invalid Envfiles fail rather than falling back to encrypting everything. The Envfile itself is never modified.
2358
-
2359
- ```sh
2360
- $ echo "HELLO=World" > .env
2361
-
2362
- $ dotenvx encrypt
2363
- ◈ encrypted (.env) + local key (.env.keys)
2364
- ⮕ next run [dotenvx gitignore --pattern .env.keys] to gitignore .env.keys
2365
- ⮕ next run [DOTENV_PRIVATE_KEY='122...0b8' dotenvx run -- yourcommand] to test decryption locally
2366
- ```
2367
-
2368
- </details>
2369
- <details><summary>`encrypt -f`</summary><br>
2370
-
2371
- Encrypt the contents of a specified `.env` file to an encrypted `.env` file.
2372
-
2373
- ```sh
2374
- $ echo "HELLO=World" > .env
2375
- $ echo "HELLO=Production" > .env.production
2376
-
2377
- $ dotenvx encrypt -f .env.production
2378
- ◈ encrypted (.env.production) + local key (.env.keys)
2379
- ⮕ next run [dotenvx gitignore --pattern .env.keys] to gitignore .env.keys
2380
- ⮕ next run [DOTENV_PRIVATE_KEY='bff...bc4' dotenvx run -- yourcommand] to test decryption locally
2381
- ```
2382
-
2383
- </details>
2384
- <details><summary>`encrypt --no-native`</summary><br>
2385
-
2386
- Turn off OS secret store lookups for encrypt.
2387
-
2388
- ```sh
2389
- $ dotenvx encrypt --no-native
2390
- ◈ encrypted (.env)
2391
- ```
2392
-
2393
- </details>
2394
- <details><summary>`encrypt --no-armor`</summary><br>
2395
-
2396
- Turn off [Dotenvx Armor ⛨](https://dotenvx.com/armor) features for encrypt.
2397
-
2398
- ```sh
2399
- $ dotenvx encrypt --no-armor
2400
- ◈ encrypted (.env)
2401
- ```
2402
-
2403
- </details>
2404
- <details><summary>`encrypt --token`</summary><br>
2405
-
2406
- Set the Armor token.
2407
-
2408
- ```sh
2409
- $ dotenvx encrypt --token token
2410
- ◈ encrypted (.env) · armored ⛨
2411
- ```
2412
-
2413
- </details>
2414
- <details><summary>`encrypt --no-create`</summary><br>
2415
-
2416
- Do not create a missing `.env` file.
2417
-
2418
- ```sh
2419
- $ dotenvx encrypt -f .env.production --no-create
2420
- ```
2421
-
2422
- </details>
2423
- <details><summary>`encrypt -fk`</summary><br>
2424
-
2425
- Specify a custom private-key file when using file storage.
2426
-
2427
- ```sh
2428
- $ mkdir -p apps/app1
2429
- $ echo "HELLO=World" > apps/app1/.env
2430
-
2431
- $ dotenvx encrypt -fk .env.keys -f apps/app1/.env
2432
- ◈ encrypted (apps/app1/.env)
2433
- ```
2434
-
2435
- Put it to use.
2436
-
2437
- ```sh
2438
- $ dotenvx run -fk .env.keys -f apps/app1/.env
2439
- ```
2440
-
2441
- Use with a relative path.
2442
-
2443
- ```sh
2444
- $ cd apps/app1
2445
- $ dotenvx run -fk ../../.env.keys -f .env
2446
- ```
2447
-
2448
- </details>
2449
- <details><summary>`encrypt -k`</summary><br>
2450
-
2451
- Specify the key(s) to encrypt by passing `--key`.
2452
-
2453
- ```sh
2454
- $ echo "HELLO=World\nHELLO2=Universe" > .env
2455
-
2456
- $ dotenvx encrypt -k HELLO2
2457
- ◈ encrypted (.env)
2458
- ```
2459
-
2460
- Even specify a glob pattern.
2461
-
2462
- ```sh
2463
- $ echo "HELLO=World\nHOLA=Mundo" > .env
2464
-
2465
- $ dotenvx encrypt -k "HE*"
2466
- ◈ encrypted (.env)
2467
- ```
2468
-
2469
- </details>
2470
- <details><summary>`encrypt -ek`</summary><br>
2471
-
2472
- Specify the key(s) to NOT encrypt by passing `--exclude-key`.
2473
-
2474
- ```sh
2475
- $ echo "HELLO=World\nHELLO2=Universe" > .env
2476
-
2477
- $ dotenvx encrypt -ek HELLO
2478
- ◈ encrypted (.env)
2479
- ```
2480
-
2481
- Even specify a glob pattern.
2482
-
2483
- ```sh
2484
- $ echo "HELLO=World\nHOLA=Mundo" > .env
2485
-
2486
- $ dotenvx encrypt -ek "HO*"
2487
- ◈ encrypted (.env)
2488
- ```
2489
-
2490
- </details>
2491
- <details><summary>`encrypt KEY_PLAIN`</summary><br>
2492
-
2493
- Skip encryption for keys ending in `_PLAIN`.
2494
-
2495
- ```sh
2496
- $ echo "HELLO=World\nHELLO_PLAIN=visible" > .env
2497
-
2498
- $ dotenvx encrypt
2499
- ◈ encrypted (.env)
2500
- ```
2501
-
2502
- `HELLO` is encrypted. `HELLO_PLAIN` stays plaintext.
2503
-
2504
- </details>
2505
- <details><summary>`encrypt --stdout`</summary><br>
2506
-
2507
- Encrypt the contents of a `.env` file and send to stdout.
2508
-
2509
- ```sh
2510
- $ echo "HELLO=World" > .env
2511
- $ dotenvx encrypt --stdout
2512
- #/-------------------[DOTENV_PUBLIC_KEY]--------------------/
2513
- #/ public-key encryption for .env files /
2514
- #/ [how it works](https://dotenvx.com/docs/quickstart/encryption) /
2515
- #/----------------------------------------------------------/
2516
- DOTENV_PUBLIC_KEY="034af93e93708b994c10f236c96ef88e47291066946cce2e8d98c9e02c741ced45"
2517
- # .env
2518
- HELLO="encrypted:BDqDBibm4wsYqMpCjTQ6BsDHmMadg9K3dAt+Z9HPMfLEIRVz50hmLXPXRuDBXaJi/LwWYEVUNiq0HISrslzQPaoyS8Lotg3gFWJTsNCdOWnqpjF2xNUX2RQiP05kAbEXM6MWVjDr"
2519
- ```
2520
-
2521
- or send to a file:
2522
-
2523
- ```sh
2524
- $ echo "HELLO=World" > .env
2525
- $ dotenvx encrypt --stdout > somefile.txt
2526
- ```
2527
-
2528
- </details>
2529
- <details><summary>`decrypt`</summary><br>
2530
-
2531
- Decrypt the contents of an encrypted `.env` file to an unencrypted `.env` file.
2532
-
2533
- ```sh
2534
- $ echo "HELLO=World" > .env
2535
- $ dotenvx encrypt
2536
- ◈ encrypted (.env)
2537
- $ dotenvx decrypt
2538
- ◇ decrypted (.env)
2539
- ```
2540
-
2541
- </details>
2542
- <details><summary>`decrypt --no-native`</summary><br>
2543
-
2544
- Turn off OS secret store lookups for decrypt.
2545
-
2546
- ```sh
2547
- $ dotenvx decrypt --no-native
2548
- ◇ decrypted (.env)
2549
- ```
2550
-
2551
- </details>
2552
- <details><summary>`decrypt --no-armor`</summary><br>
2553
-
2554
- Turn off [Dotenvx Armor ⛨](https://dotenvx.com/armor) features for decrypt.
2555
-
2556
- ```sh
2557
- $ dotenvx decrypt --no-armor
2558
- ◇ decrypted (.env)
2559
- ```
2560
-
2561
- </details>
2562
- <details><summary>`decrypt -f`</summary><br>
2563
-
2564
- Decrypt the contents of a specified encrypted `.env` file to an unencrypted `.env` file.
2565
-
2566
- ```sh
2567
- $ echo "HELLO=World" > .env
2568
- $ echo "HELLO=Production" > .env.production
2569
-
2570
- $ dotenvx encrypt -f .env.production
2571
- ◈ encrypted (.env.production)
2572
- $ dotenvx decrypt -f .env.production
2573
- ◇ decrypted (.env.production)
2574
- ```
2575
-
2576
- </details>
2577
- <details><summary>`decrypt -fk`</summary><br>
2578
-
2579
- Specify a custom private-key file when using file storage.
2580
-
2581
- ```sh
2582
- $ mkdir -p apps/app1
2583
- $ echo "HELLO=World" > apps/app1/.env
2584
-
2585
- $ dotenvx encrypt -fk .env.keys -f apps/app1/.env
2586
- ◈ encrypted (apps/app1/.env)
2587
- $ dotenvx decrypt -fk .env.keys -f apps/app1/.env
2588
- ◇ decrypted (apps/app1/.env)
2589
- ```
2590
-
2591
- </details>
2592
- <details><summary>`decrypt -k`</summary><br>
2593
-
2594
- Decrypt the contents of a specified key inside an encrypted `.env` file.
2595
-
2596
- ```sh
2597
- $ echo "HELLO=World\nHOLA=Mundo" > .env
2598
- $ dotenvx encrypt
2599
- ◈ encrypted (.env)
2600
- $ dotenvx decrypt -k HELLO
2601
- ◇ decrypted (.env)
2602
- ```
2603
-
2604
- Even specify a glob pattern.
2605
-
2606
- ```sh
2607
- $ echo "HELLO=World\nHOLA=Mundo" > .env
2608
- $ dotenvx encrypt
2609
- ◈ encrypted (.env)
2610
- $ dotenvx decrypt -k "HE*"
2611
- ◇ decrypted (.env)
2612
- ```
2613
-
2614
- </details>
2615
- <details><summary>`decrypt -ek`</summary><br>
2616
-
2617
- Decrypt the contents inside an encrypted `.env` file except for an excluded key.
2618
-
2619
- ```sh
2620
- $ echo "HELLO=World\nHOLA=Mundo" > .env
2621
- $ dotenvx encrypt
2622
- ◈ encrypted (.env)
2623
- $ dotenvx decrypt -ek HOLA
2624
- ◇ decrypted (.env)
2625
- ```
2626
-
2627
- Even specify a glob pattern.
2628
-
2629
- ```sh
2630
- $ echo "HELLO=World\nHOLA=Mundo" > .env
2631
- $ dotenvx encrypt
2632
- ◈ encrypted (.env)
2633
- $ dotenvx decrypt -ek "HO*"
2634
- ◇ decrypted (.env)
2635
- ```
2636
-
2637
- </details>
2638
- <details><summary>`decrypt --stdout`</summary><br>
2639
-
2640
- Decrypt the contents of an encrypted `.env` file and send to stdout.
2641
-
2642
- ```sh
2643
- $ dotenvx decrypt --stdout
2644
- #/-------------------[DOTENV_PUBLIC_KEY]--------------------/
2645
- #/ public-key encryption for .env files /
2646
- #/ [how it works](https://dotenvx.com/docs/quickstart/encryption) /
2647
- #/----------------------------------------------------------/
2648
- DOTENV_PUBLIC_KEY="034af93e93708b994c10f236c96ef88e47291066946cce2e8d98c9e02c741ced45"
2649
- # .env
2650
- HELLO="World"
2651
- ```
2652
-
2653
- or send to a file:
2654
-
2655
- ```sh
2656
- $ dotenvx decrypt --stdout > somefile.txt
2657
- ```
2658
-
2659
- </details>
2660
- <details><summary>`decrypt --stdout --mask`</summary><br>
2661
-
2662
- Decrypt the contents of an encrypted `.env` file to stdout with its values masked. The encrypted `.env` file remains unchanged.
2663
-
2664
- ```sh
2665
- $ echo "SECRET=abcdefghijkl" > .env
2666
- $ dotenvx encrypt
2667
- ◈ encrypted (.env)
2668
-
2669
- $ dotenvx decrypt --stdout --mask
2670
- ...
2671
- SECRET="abcdef******"
2672
- ```
2673
-
2674
- Pass a number to control how many characters are visible, such as `--mask 0` to fully mask values.
2675
-
2676
- </details>
2677
- <details><summary>`keypair`</summary><br>
2678
-
2679
- Print public/private keys for `.env` file.
2680
-
2681
- ```sh
2682
- $ echo "HELLO=World" > .env
2683
- $ dotenvx encrypt
2684
-
2685
- $ dotenvx keypair
2686
- {"DOTENV_PUBLIC_KEY":"<publicKey>","DOTENV_PRIVATE_KEY":"<privateKey>"}
2687
- ```
2688
-
2689
- </details>
2690
- <details><summary>`keypair --no-native`</summary><br>
2691
-
2692
- Turn off OS secret store lookups for keypair.
2693
-
2694
- ```sh
2695
- $ dotenvx keypair --no-native
2696
- {"DOTENV_PUBLIC_KEY":"<publicKey>","DOTENV_PRIVATE_KEY":"<privateKey>"}
2697
- ```
2698
-
2699
- </details>
2700
- <details><summary>`keypair --no-armor`</summary><br>
2701
-
2702
- Turn off [Dotenvx Armor ⛨](https://dotenvx.com/armor) features for keypair.
2703
-
2704
- ```sh
2705
- $ dotenvx keypair --no-armor
2706
- {"DOTENV_PUBLIC_KEY":"<publicKey>","DOTENV_PRIVATE_KEY":"<privateKey>"}
2707
- ```
2708
-
2709
- </details>
2710
- <details><summary>`keypair -f`</summary><br>
2711
-
2712
- Print public/private keys for `.env.production` file.
2713
-
2714
- ```sh
2715
- $ echo "HELLO=Production" > .env.production
2716
- $ dotenvx encrypt -f .env.production
2717
-
2718
- $ dotenvx keypair -f .env.production
2719
- {"DOTENV_PUBLIC_KEY_PRODUCTION":"<publicKey>","DOTENV_PRIVATE_KEY_PRODUCTION":"<privateKey>"}
2720
- ```
2721
-
2722
- </details>
2723
- <details><summary>`keypair -fk`</summary><br>
2724
-
2725
- Print keys from a custom private-key file when using file storage.
2726
-
2727
- ```sh
2728
- $ mkdir -p apps/app1
2729
- $ echo "HELLO=World" > apps/app1/.env
2730
- $ dotenvx encrypt -fk .env.keys -f apps/app1/.env
2731
-
2732
- $ dotenvx keypair -fk .env.keys -f apps/app1/.env
2733
- {"DOTENV_PUBLIC_KEY":"<publicKey>","DOTENV_PRIVATE_KEY":"<privateKey>"}
2734
- ```
2735
-
2736
- </details>
2737
- <details><summary>`keypair DOTENV_PRIVATE_KEY`</summary><br>
2738
-
2739
- Print specific keypair for `.env` file.
2740
-
2741
- ```sh
2742
- $ echo "HELLO=World" > .env
2743
- $ dotenvx encrypt
2744
-
2745
- $ dotenvx keypair DOTENV_PRIVATE_KEY
2746
- <privateKey>
2747
- ```
2748
-
2749
- </details>
2750
- <details><summary>`keypair --format shell`</summary><br>
2751
-
2752
- Print a shell formatted response of public/private keys.
2753
-
2754
- ```sh
2755
- $ echo "HELLO=World" > .env
2756
- $ dotenx encrypt
2757
-
2758
- $ dotenvx keypair --format shell
2759
- DOTENV_PUBLIC_KEY=<publicKey> DOTENV_PRIVATE_KEY=<privateKey>
2760
- ```
2761
-
2762
- </details>
2763
- <details><summary>`keypair --format colon`</summary><br>
2764
-
2765
- Return a colon-formatted keypair.
2766
-
2767
- ```sh
2768
- $ dotenvx keypair --format colon
2769
- DOTENV_PUBLIC_KEY:<publicKey> DOTENV_PRIVATE_KEY:<privateKey>
2770
- ```
2771
-
2772
- </details>
2773
- <details><summary>`keypair --format json`</summary><br>
2774
-
2775
- Return a JSON-formatted keypair.
2776
-
2777
- ```sh
2778
- $ dotenvx keypair --format json
2779
- {"DOTENV_PUBLIC_KEY":"<publicKey>","DOTENV_PRIVATE_KEY":"<privateKey>"}
2780
- ```
2781
-
2782
- </details>
2783
- <details><summary>`keypair --pretty-print`</summary><br>
2784
-
2785
- Make the JSON output more readable.
2786
-
2787
- ```sh
2788
- $ dotenvx keypair --pretty-print
2789
- {
2790
- "DOTENV_PUBLIC_KEY": "<publicKey>",
2791
- "DOTENV_PRIVATE_KEY": "<privateKey>"
2792
- }
2793
- ```
2794
-
2795
- </details>
2796
- <details><summary>`hidden`</summary><br>
2797
-
2798
- Dotenvx has a slew of hidden commands.
2799
-
2800
- [See their documentation →](https://dotenvx.com/docs/cli/hidden/)
2801
-
2802
- </details>
2803
-
2804
- &nbsp;
2805
-
2806
- ### Library 📦
2807
-
2808
- Use dotenvx directly in code.
2809
-
2810
- <details><summary>`config()`</summary><br>
2811
-
2812
- Use directly in node.js code.
2813
-
2814
- ```ini
2815
- # .env
2816
- HELLO="World"
2817
- ```
2818
-
2819
- ```js
2820
- // index.js
2821
- require('@dotenvx/dotenvx').config()
2822
-
2823
- console.log(`Hello ${process.env.HELLO}`)
2824
- ```
10
+ From Forge with Node.js 20+ and a Rust toolchain installed:
2825
11
 
2826
12
  ```sh
2827
- $ node index.js
2828
- [dotenvx@1.X.X] injecting env (1) from .env
2829
- Hello World
13
+ npm run build:dotenvx-nodejs
14
+ npm run test:dotenvx-nodejs
2830
15
  ```
2831
16
 
2832
- It defaults to looking for a `.env` file.
2833
-
2834
- </details>
2835
- <details><summary>`config(mask: true)` - mask</summary><br>
17
+ To install the local prototype in another project, pack and install the main
18
+ and matching platform packages together as described below.
2836
19
 
2837
- Inject and return masked values. By default, up to the first six characters are visible.
20
+ The package keeps the `@dotenvx/dotenvx` name and starts at `3.0.0-beta.0`.
21
+ There are no install-time downloads or compilation hooks. A local build writes
22
+ the current platform’s addon and default CLI to `native/` and prepares its npm
23
+ package under `dist/npm/`. The main npm package contains JavaScript only; native
24
+ files are delivered through exact-version optional platform dependencies.
2838
25
 
2839
- ```ini
2840
- # .env
2841
- SECRET="abcdefghijkl"
2842
- ```
26
+ ## Usage
2843
27
 
2844
28
  ```js
2845
- // index.js
2846
29
  const dotenvx = require('@dotenvx/dotenvx')
2847
- const result = dotenvx.config({ mask: true, quiet: true })
2848
-
2849
- console.log(process.env.SECRET)
2850
- console.log(result.parsed.SECRET)
2851
- ```
2852
-
2853
- ```sh
2854
- $ node index.js
2855
- abcdef******
2856
- abcdef******
2857
- ```
2858
-
2859
- Set `mask: 0` to fully mask values.
2860
-
2861
- </details>
2862
- <details><summary>`config(path: ['.env.local', '.env'])` - multiple files</summary><br>
2863
-
2864
- Specify path(s) to multiple .env files.
2865
-
2866
- ```ini
2867
- # .env.local
2868
- HELLO="Me"
2869
- ```
2870
-
2871
- ```ini
2872
- # .env
2873
- HELLO="World"
2874
- ```
2875
-
2876
- ```js
2877
- // index.js
2878
- require('@dotenvx/dotenvx').config({path: ['.env.local', '.env']})
2879
-
2880
- // esm
2881
- // import dotenvx from "@dotenvx/dotenvx";
2882
- // dotenvx.config({path: ['.env.local', '.env']});
2883
-
2884
- console.log(`Hello ${process.env.HELLO}`)
2885
- ```
2886
-
2887
- ```sh
2888
- $ node index.js
2889
- [dotenvx@1.X.X] injecting env (1) from .env.local, .env
2890
- Hello Me
2891
- ```
2892
-
2893
- </details>
2894
- <details><summary>`config(overload: true)` - overload</summary><br>
2895
-
2896
- Use `overload` to overwrite the prior set value.
2897
-
2898
- ```ini
2899
- # .env.local
2900
- HELLO="Me"
30
+ const result = dotenvx.config()
31
+ console.log(process.env.HELLO)
2901
32
  ```
2902
33
 
2903
- ```ini
2904
- # .env
2905
- HELLO="World"
2906
- ```
34
+ ES modules support named and default imports:
2907
35
 
2908
36
  ```js
2909
- // index.js
2910
- require('@dotenvx/dotenvx').config({path: ['.env.local', '.env'], overload: true})
2911
-
2912
- // esm
2913
- // import dotenvx from "@dotenvx/dotenvx";
2914
- // dotenvx.config({path: ['.env.local', '.env'], overload: true});
2915
-
2916
- console.log(`Hello ${process.env.HELLO}`)
2917
- ```
2918
-
2919
- ```sh
2920
- $ node index.js
2921
- [dotenvx@1.X.X] injecting env (1) from .env.local, .env
2922
- Hello World
2923
- ```
2924
-
2925
- </details>
2926
- <details><summary>`config(quiet: true)` - quiet</summary><br>
2927
-
2928
- Suppress all output (except errors).
2929
-
2930
- ```ini
2931
- # .env
2932
- HELLO="World"
37
+ import dotenvx, { config } from '@dotenvx/dotenvx'
38
+ config({ path: '.env.production', strict: true })
2933
39
  ```
2934
40
 
2935
- ```js
2936
- // index.js
2937
- require('@dotenvx/dotenvx').config({path: ['.env.missing', '.env'], quiet: true})
2938
-
2939
- // esm
2940
- // import dotenvx from "@dotenvx/dotenvx";
2941
- // dotenvx.config({path: ['.env.missing', '.env'], quiet: true});
2942
-
2943
- console.log(`Hello ${process.env.HELLO}`)
2944
- ```
41
+ Preload before application modules execute:
2945
42
 
2946
43
  ```sh
2947
- $ node index.js
2948
- Error: [MISSING_ENV_FILE] missing .env.missing file (/path/to/.env.missing)
2949
- Hello World
44
+ node --require @dotenvx/dotenvx/config app.cjs
45
+ node --import @dotenvx/dotenvx/config app.mjs
2950
46
  ```
2951
47
 
2952
- You can also set `DOTENV_QUIET=true`.
48
+ `import '@dotenvx/dotenvx/config'` also works. `DOTENV_CONFIG_PATH` selects a
49
+ preload file when `DOTENV_FILE` / `DOTENV_PATH` are absent. Quiet mode accepts
50
+ `DOTENV_QUIET` and the legacy `DOTENV_CONFIG_QUIET`.
2953
51
 
2954
- ```sh
2955
- $ DOTENV_QUIET=true node index.js
2956
- Error: [MISSING_ENV_FILE] missing .env.missing file (/path/to/.env.missing)
2957
- Hello World
2958
- ```
52
+ ## Core API
2959
53
 
2960
- </details>
2961
- <details><summary>`config(strict: true)` - strict</summary><br>
54
+ - `config(options)` synchronously resolves values and populates `process.env`,
55
+ returning `{ parsed, error? }`. `processEnv` selects a different environment
56
+ object to read and populate. Existing values win unless `overload` / `override`
57
+ is enabled. Strict or fatal errors throw before any resolved values are injected.
58
+ - `parse(stringOrBuffer, options)` uses Rust primitives without filesystem,
59
+ policy, or custody lookups. It expands values and decrypts using supplied
60
+ environment keys or `privateKey`, without changing the supplied environment.
61
+ - `get(key?, options)` resolves synchronously and returns the value directly.
62
+ `getSync` is an alias of the same function (`getSync === get`). Neither mutates
63
+ the environment. Calls block while reading files or resolving custody, and
64
+ failures throw synchronously. `await get(...)` still works with the returned
65
+ value; Promise methods such as `.then()` and `.catch()` are not supported.
66
+ With no key, they return the resolved object; `all: true` includes existing
67
+ environment values. `format` supports `eval`, `eval-export`, `shell`, and `colon`.
2962
68
 
2963
- Exit with code `1` if any errors are encountered - like a missing .env file or decryption failure.
69
+ Files can be paths, file URLs, arrays, or directories. `envs` selects ordered
70
+ `{ type: 'envFile', value: path }` and `{ type: 'env', value: source }` inputs.
71
+ Explicit `envs` override `path`. `envKeysFile` / `keyFiles`
72
+ select private-key files. Conventions and implicit discovery are resolved in Rust.
73
+ This prototype supports UTF-8 files and includes TypeScript declarations.
2964
74
 
2965
- ```ini
2966
- # .env
2967
- HELLO="World"
2968
- ```
75
+ Local `.env.keys` and environment private keys work without the CLI. Stored-key
76
+ custody uses `dotenvx sdk keyring` on PATH, like the other language SDKs. The CLI
77
+ needs `sdk` and the requested custody feature. Keys returned by the CLI remain
78
+ in the internal keyring and are not injected into the application's environment.
79
+ When using a custom `processEnv`, include the PATH and provider settings it needs.
80
+ Secret reference resolution is opt-in with `resolveReferences: true`.
2969
81
 
2970
- ```js
2971
- // index.js
2972
- require('@dotenvx/dotenvx').config({path: ['.env.missing', '.env'], strict: true})
82
+ Dotenvx.toml redaction is installed before diagnostics and injection. Console
83
+ output and stream writes are protected, including secrets split between writes.
2973
84
 
2974
- // esm
2975
- // import dotenvx from "@dotenvx/dotenvx";
2976
- // dotenvx.config({path: ['.env.missing', '.env'], strict: true});
85
+ ## npm CLI
2977
86
 
2978
- console.log(`Hello ${process.env.HELLO}`)
2979
- ```
87
+ The matching optional platform package includes a default Rust CLI executable
88
+ alongside the SDK addon. The
89
+ npm launcher first looks for an installed standalone `dotenvx` on PATH, then
90
+ falls back to the bundled default CLI. An existing Armor or custom build is used
91
+ automatically, with its commands and features preserved. No separate curl
92
+ installation or install-time download is required for the bundled default.
2980
93
 
2981
94
  ```sh
2982
- $ node index.js
2983
- Error: [MISSING_ENV_FILE] missing .env.missing file (/path/to/.env.missing)
95
+ npx dotenvx encrypt
96
+ npx dotenvx run -- node app.cjs
2984
97
  ```
2985
98
 
2986
- </details>
2987
- <details><summary>`config(ignore:)` - ignore</summary><br>
99
+ Existing npm scripts such as `"start": "dotenvx run -- node app.cjs"` use the same
100
+ launcher, which forwards arguments, terminal input/output, exit status, and
101
+ termination signals without interpreting commands. The bundled CLI uses the
102
+ default feature set from Forge's CLI catalog. Command behavior follows the
103
+ selected Rust CLI rather than the former JavaScript CLI. `dotenvx --version`
104
+ reports the selected CLI's version; the prototype SDK and CLI currently have
105
+ separate version numbers.
2988
106
 
2989
- Use `ignore` to suppress specific errors like `MISSING_ENV_FILE`.
107
+ PATH discovery skips script wrappers, including npm's own shims and older
108
+ JavaScript dotenvx CLIs, to avoid recursion. It selects the first executable
109
+ native binary named `dotenvx` (`dotenvx.exe` on Windows). The launcher does not
110
+ fall back if that installed CLI rejects a command or exits with an error.
111
+ Installing or updating a standalone CLI therefore changes what `npx dotenvx`
112
+ runs, even if the npm dependency is pinned.
2990
113
 
2991
- ```ini
2992
- # .env
2993
- HELLO="World"
2994
- ```
2995
-
2996
- ```js
2997
- // index.js
2998
- require('@dotenvx/dotenvx').config({path: ['.env.missing', '.env'], ignore: ['MISSING_ENV_FILE']})
114
+ Optionally, `DOTENVX_CLI` selects an explicit executable path ahead of PATH
115
+ discovery. No override is needed for Armor or custom builds on PATH. This setting
116
+ selects both the npm CLI executable and the SDK's delegated custody executable.
117
+ SDK custody uses the same standalone-binary discovery and packaged fallback as
118
+ the launcher, so it also works without a global CLI on PATH.
2999
119
 
3000
- // esm
3001
- // import dotenvx from "@dotenvx/dotenvx";
3002
- // dotenvx.config({path: ['.env.missing', '.env'], ignore: ['MISSING_ENV_FILE']});
120
+ Decryption first checks matching environment private keys, then configured local
121
+ key files (including `.env.keys`), then the custodian named in the public-key
122
+ header. `armor pull` leaves the Armor custody metadata in place, but the pulled
123
+ matching local key can decrypt without a remote lookup. `armor down` additionally
124
+ removes remote custody and updates the header; local fallback does neither.
3003
125
 
3004
- console.log(`Hello ${process.env.HELLO}`)
3005
- ```
126
+ ## Migrating from 2.x
3006
127
 
3007
- ```sh
3008
- $ node index.js
3009
- [dotenvx@1.X.X] injecting env (1) from .env
3010
- Hello World
3011
- ```
128
+ The [central dotenvx 3.0 breaking-changes list](../README.md#dotenvx-30-breaking-changes)
129
+ records the removed SDK APIs (`set`, `ls`, `withEvents`, and public logging/color
130
+ helpers), migration guidance, and the decision to defer shared SDK event tracking.
3012
131
 
3013
- </details>
3014
- <details><summary>`config(envKeysFile:)` - envKeysFile</summary><br>
132
+ ## Platform packages and releases
3015
133
 
3016
- Use `envKeysFile` to specify a custom private-key file when using file storage.
134
+ Forge publishes these packages at the same version as `@dotenvx/dotenvx`:
3017
135
 
3018
- ```ini
3019
- # .env
3020
- HELLO="World"
3021
- ```
136
+ | Runtime | Package |
137
+ | --- | --- |
138
+ | macOS ARM64 | `@dotenvx/dotenvx-darwin-arm64` |
139
+ | macOS x64 | `@dotenvx/dotenvx-darwin-x86_64` |
140
+ | Linux glibc ARM64 | `@dotenvx/dotenvx-linux-arm64` |
141
+ | Linux glibc x64 | `@dotenvx/dotenvx-linux-x86_64` |
142
+ | Linux musl ARM64 | `@dotenvx/dotenvx-linux-arm64-musl` |
143
+ | Linux musl x64 | `@dotenvx/dotenvx-linux-x86_64-musl` |
144
+ | Windows ARM64 | `@dotenvx/dotenvx-windows-arm64` |
145
+ | Windows x64 | `@dotenvx/dotenvx-windows-x86_64` |
3022
146
 
3023
- ```js
3024
- // index.js
3025
- require('@dotenvx/dotenvx').config({path: ['.env'], envKeysFile: '../../.env.keys'})
3026
- ```
147
+ Each package contains `dotenvx.node` and `dotenvx` (`dotenvx.exe` on Windows),
148
+ with `os`, `cpu`, and Linux `libc` filters. Existing binary package names are
149
+ reused; historical architecture aliases such as `amd64` are not additional SDK
150
+ dependencies. Linux glibc builds target glibc 2.28 or newer. Alpine uses separate
151
+ musl builds. The loader has no JavaScript fallback.
3027
152
 
3028
- </details>
3029
- <details><summary>`config(convention:)` - convention</summary><br>
153
+ Do not omit optional dependencies when using the SDK. If they are omitted,
154
+ CLI commands can still use an installed standalone CLI, but SDK loading fails
155
+ with a reinstall hint. Local development can use the current platform's files
156
+ in `native/`; those files are excluded from the main npm tarball.
3030
157
 
3031
- Set a convention when using `dotenvx.config()`. This allows you to use the same file loading order as the CLI without needing to specify each file individually.
158
+ For a local packaged install, build and pack both packages, then install the two
159
+ resulting tarballs together. Unpublished optional packages for other platforms
160
+ can be skipped with npm's `--offline` flag:
3032
161
 
3033
162
  ```sh
3034
- # Setup environment files
3035
- $ echo "HELLO=development local" > .env.development.local
3036
- $ echo "HELLO=local" > .env.local
3037
- $ echo "HELLO=development" > .env.development
3038
- $ echo "HELLO=env" > .env
163
+ npm run build:dotenvx-nodejs
164
+ npm pack ./dotenvx-nodejs/dist/npm/dotenvx-darwin-arm64 --ignore-scripts
165
+ npm pack ./dotenvx-nodejs --ignore-scripts
166
+ npm install --offline ./dotenvx-dotenvx-3.0.0-beta.0.tgz ./dotenvx-dotenvx-darwin-arm64-3.0.0-beta.0.tgz
3039
167
  ```
3040
168
 
3041
- ```js
3042
- // index.js
3043
- require('@dotenvx/dotenvx').config({ convention: 'nextjs' })
3044
-
3045
- console.log(`Hello ${process.env.HELLO}`)
3046
- ```
169
+ Substitute the current platform package and version. A direct local directory
170
+ install alone does not assemble optional packages for the consuming project.
3047
171
 
3048
- ```sh
3049
- $ NODE_ENV=development node index.js
3050
- [dotenvx@1.28.0] injecting env (1) from .env.development.local, .env.local, .env.development, .env
3051
- Hello development local
3052
- ```
172
+ `.github/workflows/nodejs.yml` builds and tests all eight native targets.
173
+ Pushing a matching `nodejs-v<version>` tag publishes the eight platform packages
174
+ under `next`, waits for npm to serve all eight exact versions, then prepares and
175
+ tests the core `@dotenvx/dotenvx` wrapper across all eight platforms before
176
+ publishing it under `next`. **Existing `latest` tags stay unchanged.** The source
177
+ core package stays private; only the validated staged wrapper is publishable.
178
+ Stable, RC, and other non-beta versions are rejected.
3053
179
 
3054
- This is equivalent to using `--convention=nextjs` with the CLI:
180
+ From a clean working tree, prepare the next Node.js beta with:
3055
181
 
3056
182
  ```sh
3057
- $ dotenvx run --convention=nextjs -- node index.js
183
+ npm run version:nodejs patch
3058
184
  ```
3059
185
 
3060
- You can also set `DOTENV_CONVENTION=nextjs`.
186
+ Here `patch` advances the beta counter: `3.0.0-beta.0` becomes
187
+ `3.0.0-beta.1`, retaining the `3.0.0` release target. The helper synchronizes the
188
+ npm/platform dependency versions, lockfile, and adapter Cargo versions, then
189
+ creates a local commit and `nodejs-v<version>` tag. It does not publish or push.
190
+ You can also include `nodejs` in `npm run version:batch -- cli,nodejs patch`
191
+ (with optional `--push`). The batch rejects `minor` and `major` up front whenever
192
+ `nodejs` is selected; `patch` still advances only the beta counter.
193
+ It prints the exact atomic push command for that commit and tag, for example:
3061
194
 
3062
195
  ```sh
3063
- $ DOTENV_CONVENTION=nextjs node index.js
3064
- ```
3065
-
3066
- </details>
3067
- <details><summary>`config(path: directory, convention: 'nextjs')` - directory</summary><br>
3068
-
3069
- Use a directory as `path` to make it the base for convention files. This is useful when loading a workspace's env files from a monorepo root.
3070
-
3071
- ```js
3072
- // index.js
3073
- require('@dotenvx/dotenvx').config({
3074
- path: 'apps/web',
3075
- convention: 'nextjs'
3076
- })
3077
- ```
3078
-
3079
- This loads the convention from `apps/web`:
3080
-
3081
- ```text
3082
- apps/web/.env.development.local
3083
- apps/web/.env.local
3084
- apps/web/.env.development
3085
- apps/web/.env
3086
- ```
3087
-
3088
- </details>
3089
- <details><summary>`config(noArmor:)` - noArmor</summary><br>
3090
-
3091
- Turn off [Dotenvx Armor ⛨](https://dotenvx.com/armor) features.
3092
-
3093
- ```js
3094
- // index.js
3095
- require('@dotenvx/dotenvx').config({noArmor: true})
3096
- ```
3097
-
3098
- </details>
3099
- <details><summary>`config(no1Password:)` - no1Password</summary><br>
3100
-
3101
- By default, `config()` automatically resolves `op://` values through the installed [1Password CLI](https://developer.1password.com/docs/cli/get-started/).
3102
-
3103
- ```ini
3104
- # .env
3105
- API_KEY=op://Personal/my_api_key/password
3106
- ```
3107
-
3108
- ```js
3109
- // index.js
3110
- require('@dotenvx/dotenvx').config()
3111
-
3112
- console.log(process.env.API_KEY)
3113
- ```
3114
-
3115
- Set `no1Password` to leave `op://` values unresolved and avoid calling `op`.
3116
-
3117
- ```js
3118
- // index.js
3119
- require('@dotenvx/dotenvx').config({no1Password: true})
3120
- ```
3121
-
3122
- </details>
3123
- <details><summary>`config(noBitwarden:)` - noBitwarden</summary><br>
3124
-
3125
- By default, `config()` automatically resolves `bw://` values through the installed [Bitwarden Password Manager CLI](https://bitwarden.com/help/cli/).
3126
-
3127
- ```ini
3128
- # .env
3129
- API_KEY="bw://My GitHub Account/password"
3130
- ```
3131
-
3132
- ```js
3133
- // index.js
3134
- require('@dotenvx/dotenvx').config()
3135
-
3136
- console.log(process.env.API_KEY)
3137
- ```
3138
-
3139
- Set `noBitwarden` to leave `bw://` values unresolved and avoid calling `bw`.
3140
-
3141
- ```js
3142
- // index.js
3143
- require('@dotenvx/dotenvx').config({noBitwarden: true})
3144
- ```
3145
-
3146
- </details>
3147
- <details><summary>`parse(src)`</summary><br>
3148
-
3149
- Parse a `.env` string directly in node.js code.
3150
-
3151
- ```js
3152
- // index.js
3153
- const dotenvx = require('@dotenvx/dotenvx')
3154
- const src = 'HELLO=World'
3155
- const parsed = dotenvx.parse(src)
3156
- console.log(`Hello ${parsed.HELLO}`)
196
+ git push --atomic origin HEAD refs/tags/nodejs-v3.0.0-beta.1
3157
197
  ```
3158
198
 
3159
- ```sh
3160
- $ node index.js
3161
- Hello World
3162
- ```
199
+ Pushing the commit alone does not release anything; pushing the matching tag
200
+ triggers the full platform-and-core beta release. Manual workflow runs build only unless
201
+ `publish` is enabled, and publication requires running from the matching beta
202
+ tag. Existing `latest` tags remain untouched. To retry a release, run the
203
+ workflow from its tag with `publish` enabled. Already published versions are
204
+ reused only when tarball integrity matches. A platform publication or core test
205
+ failure stops the release before core publication. Stable and RC publication are disabled.
3163
206
 
3164
- </details>
3165
- <details><summary>`parse(src, {processEnv:})`</summary><br>
207
+ Before the first release, configure npm trusted publishing for
208
+ every platform package: repository `dotenvx/forge`, workflow `nodejs.yml`,
209
+ environment `release`. The workflow uses Node 24 and npm with OIDC support. Forge is private, so
210
+ publication explicitly disables provenance; npm does not support provenance
211
+ from private repositories, even for public packages. See the
212
+ [npm trusted publishing documentation](https://docs.npmjs.com/trusted-publishers/).
213
+ The three new package names have been initialized at `0.1.0`. The release
214
+ workflow now uses trusted publishing only and does not read an `NPM_TOKEN`
215
+ secret. No credentials are needed for build-only runs. Platform manifests also
216
+ set `publishConfig.tag` to `next`, and artifact validation rejects any other tag.
3166
217
 
3167
- Sometimes, you want to run `parse` without it accessing `process.env`. (You can pass a fake processEnv this way as well - sometimes useful.)
218
+ Forge owns the new 3.x beta platform packages and core wrapper releases.
219
+ Existing 2.x versions remain unchanged.
3168
220
 
3169
- ```js
3170
- // index.js
3171
- const dotenvx = require('@dotenvx/dotenvx')
3172
- const src = 'USER=Me'
3173
- const parsed = dotenvx.parse(src, { processEnv: {} })
3174
- console.log(`Hello ${parsed.USER}`)
3175
- ```
3176
221
 
3177
- ```sh
3178
- $ node index.js
3179
- Hello Me
3180
- ```
222
+ ## Core beta publication from Forge
3181
223
 
3182
- </details>
3183
- <details><summary>`parse(src, {privateKey:})`</summary><br>
224
+ Core publication follows successful platform publication automatically in
225
+ `nodejs.yml` tag releases. Preparation waits for npm's processing delay, then the
226
+ core test matrix must pass on all eight platforms. A separate `core-beta` manual
227
+ mode remains available to test or retry only the wrapper. It uses the
228
+ already-published, exact-version platform packages. It never rebuilds or
229
+ republishes the CLI or native addons and never copies code to
230
+ the legacy dotenvx repository.
3184
231
 
3185
- Decrypt an encrypted `.env` string with `privateKey`.
232
+ The source `package.json` stays private. Preparation creates a staged tarball
233
+ with `private: false`, no lifecycle scripts, and `publishConfig.tag: next`.
234
+ It validates all eight published platform versions and their metadata before
235
+ preparing the wrapper. No native files are included in the wrapper tarball.
3186
236
 
3187
- ```js
3188
- // index.js
3189
- const dotenvx = require('@dotenvx/dotenvx')
3190
- const src = 'HELLO="encrypted:BEiK4SwVe4rznIrZKW7qcnEBxo6Qxy0gv8xXiPN90N1jjhwkyVqzgoszZEI00tEeRWHsfQyJbCVy11qOEkkmERWbvOBzHve8/7WmVwyo5Z3HIOhlI45C+zmFgqmS2zMw9GPzHd9e"'
3191
- const parsed = dotenvx.parse(src, { privateKey: 'a4547dcd9d3429615a3649bb79e87edb62ee6a74b007075e9141ae44f5fb412c' })
3192
- console.log(`Hello ${parsed.HELLO}`)
3193
- ```
237
+ A local read-only registry check and package preparation is available:
3194
238
 
3195
239
  ```sh
3196
- $ node index.js
3197
- Hello World
3198
- ```
3199
- </details>
3200
- <details><summary>`set(KEY, value)`</summary><br>
3201
-
3202
- Programmatically set an environment variable.
3203
-
3204
- ```js
3205
- // index.js
3206
- const dotenvx = require('@dotenvx/dotenvx')
3207
- dotenvx.set('HELLO', 'World', { path: '.env' })
3208
- ```
3209
-
3210
- </details>
3211
- <details><summary>`set(KEY, value, {plain:})`</summary><br>
3212
-
3213
- Programmatically set a plaintext environment variable.
3214
-
3215
- ```js
3216
- // index.js
3217
- const dotenvx = require('@dotenvx/dotenvx')
3218
- dotenvx.set('HELLO', 'World', { plain: true })
3219
- ```
3220
-
3221
- </details>
3222
- <details><summary>`get(KEY)` - <i>Decryption at Access</i></summary><br>
3223
-
3224
- Programmatically get an environment variable at access/runtime.
3225
-
3226
- ```js
3227
- // index.js
3228
- const dotenvx = require('@dotenvx/dotenvx')
3229
- const decryptedValue = await dotenvx.get('HELLO')
3230
- console.log(decryptedValue)
240
+ npm run prepare:nodejs:core
3231
241
  ```
3232
242
 
3233
- This is known as *Decryption at Access* and is written about in [the whitepaper](https://dotenvx.com/dotenvx.pdf).
3234
-
3235
- </details>
3236
- <details><summary>`getSync(KEY)` - synchronous access</summary><br>
3237
-
3238
- Synchronously resolve an environment variable without populating `process.env`. This is useful in configuration files that cannot await `get()`.
3239
-
3240
- ```js
3241
- const dotenvx = require('@dotenvx/dotenvx')
3242
- const decryptedValue = dotenvx.getSync('HELLO', { path: '.env.credentials', strict: true })
3243
- ```
3244
-
3245
- `getSync()` accepts the same options as `get()`, including masking, multiple paths, and error handling. Omit the key to return all values from the selected files. It blocks while files and providers are resolved.
3246
-
3247
- If you already called `dotenvx.config()`, you can read the loaded value directly from `process.env.HELLO` instead.
3248
-
3249
- </details>
3250
- <details><summary>`get(KEY, {mask:})`</summary><br>
3251
-
3252
- Programmatically return a masked environment variable value.
3253
-
3254
- ```js
3255
- // index.js
3256
- const dotenvx = require('@dotenvx/dotenvx')
3257
- const maskedValue = await dotenvx.get('SECRET', { mask: true })
3258
- console.log(maskedValue)
3259
- ```
243
+ This produces `dist/nodejs-core/dotenvx-dotenvx-<version>.tgz` without publishing.
244
+ To exercise the staged wrapper against the published native dependencies on all
245
+ eight targets, after committing and pushing the workflow changes, dispatch:
3260
246
 
3261
247
  ```sh
3262
- $ node index.js
3263
- abcdef******
3264
- ```
3265
-
3266
- Set `mask: 0` to fully mask values.
3267
-
3268
- </details>
3269
-
3270
- &nbsp;
3271
-
3272
- ### More
3273
-
3274
- <details><summary>Settings ⚙️</summary><br>
3275
-
3276
- There are global settings available that can be configured as environment variables.
3277
-
3278
- ```ini
3279
- # config
3280
- DOTENV_CONVENTION= # set to a default convention like 'nextjs' or 'flow'
3281
- DOTENV_FILE= # path to your env file; comma-separate multiple paths
3282
- DOTENV_PATH= # synonym for DOTENV_FILE
3283
- DOTENV_F= # synonym for DOTENV_FILE
3284
- DOTENV_IGNORE= # MISSING_ENV_FILE,OTHER
3285
- DOTENV_QUIET= # set to "true" to default to --quiet
3286
-
3287
- # legacy aliases (still supported)
3288
- DOTENV_CONFIG_CONVENTION=
3289
- DOTENV_CONFIG_IGNORE=
3290
- DOTENV_CONFIG_QUIET=
3291
-
3292
- # armor
3293
- DOTENVX_ARMOR_TOKEN= # for api calls
3294
- DOTENVX_NO_ARMOR= # set to "true" to turn off Armor support
3295
-
3296
- # 1password
3297
- DOTENVX_NO_1PASSWORD= # set to "true" to turn off 1Password support
3298
-
3299
- # bitwarden
3300
- DOTENVX_NO_BITWARDEN= # set to "true" to turn off Bitwarden support
3301
- BW_SESSION= # set to bitwarden session token to bypass password prompt
3302
- ```
3303
-
3304
- </details>
3305
- <details><summary>Error Codes 🚨</summary><br>
3306
-
3307
- Dotenvx errors begin with a stable code in square brackets like `[MISSING_ENV_FILE]`.
3308
-
3309
- ```ini
3310
- # error codes
3311
- 1PASSWORD_FAILED= # a value could not be resolved with the 1Password CLI
3312
- ACCESS_APPROVAL_TIMEOUT= # an Armor access-approval request timed out
3313
- BITWARDEN_FAILED= # a value could not be resolved with the Bitwarden CLI
3314
- COMMAND_EXITED_WITH_CODE= # the command run by dotenvx exited with a non-zero status
3315
- COMMAND_SUBSTITUTION_FAILED= # a $(command) expression in an environment value could not be evaluated
3316
- DECRYPTION_FAILED= # an encrypted value could not be decrypted
3317
- FILE_NOT_WRITABLE= # dotenvx could not write to the target file
3318
- INVALID_COLOR= # the requested terminal color is invalid
3319
- INVALID_CONVENTION= # the requested environment-file convention is invalid
3320
- INVALID_PRIVATE_KEY= # a private key is malformed or otherwise invalid
3321
- INVALID_PUBLIC_KEY= # a public key is malformed or otherwise invalid
3322
- MALFORMED_ENCRYPTED_DATA= # the encrypted value is malformed
3323
- MISPAIRED_PRIVATE_KEY= # a private key does not match the existing public key
3324
- MISSING_DIRECTORY= # the requested directory does not exist
3325
- ENVSPEC_REQUIRED= # the required Envfile does not exist
3326
- MISSING_ENV_FILE= # a requested environment file does not exist
3327
- MISSING_ENV_FILES= # no .env* files were found
3328
- MISSING_ENV_KEYS_FILE= # the requested .env.keys file does not exist
3329
- MISSING_KEY= # a requested environment key does not exist
3330
- MISSING_LOG_LEVEL= # the requested log level is not supported
3331
- MISSING_PRIVATE_KEY= # the private key required to decrypt a value is missing
3332
- MISSING_PUBLIC_KEY= # the public key required to encrypt a value is missing
3333
- MISSING_REQUIRED= # validation detail for which required variables are missing; surfaced by INVALID_ENV
3334
- MISSING_VALUE= # no value was supplied for a key
3335
- NOT_FOUND= # a private key was not found in the native secret store
3336
- PRECOMMIT_HOOK_MODIFY_FAILED= # dotenvx could not update the pre-commit hook
3337
- INVALID_ENV= # resolved values do not satisfy Envfile rules
3338
- MALFORMED_ENVSPEC= # Envfile syntax or configuration is invalid
3339
- WRONG_PRIVATE_KEY= # the supplied private key cannot decrypt the value
3340
- ```
3341
-
3342
- </details>
3343
-
3344
- &nbsp;
3345
-
3346
- ## FAQ
3347
-
3348
- <details><summary>How does encryption work?</summary><br>
3349
-
3350
- Dotenvx uses Elliptic Curve Integrated Encryption Scheme (ECIES) to encrypt each secret with a unique ephemeral key, while ensuring it can be decrypted using a long-term private key.
3351
-
3352
- When you initialize encryption, a DOTENV_PUBLIC_KEY (encryption key) and DOTENV_PRIVATE_KEY (decryption key) are generated. The DOTENV_PUBLIC_KEY is used to encrypt secrets, and the DOTENV_PRIVATE_KEY is securely stored in your cloud secrets manager or .env.keys file.
3353
-
3354
- Your encrypted .env file is then safely committed to code. Even if the file is exposed, secrets remain protected since decryption requires the separate DOTENV_PRIVATE_KEY, which is never stored alongside it. Read [the whitepaper](https://dotenvx.com/dotenvx.pdf?v=README) for more details.
3355
-
3356
- </details>
3357
- <details><summary>Is it safe to commit an encrypted .env file to code?</summary><br>
3358
-
3359
- Yes. Dotenvx encrypts secrets using AES-256 with ephemeral keys, ensuring that even if the encrypted .env file is exposed, its contents remain secure. The encryption keys themselves are protected using Secp256k1 elliptic curve cryptography, which is widely used for secure key exchange in technologies like Bitcoin.
3360
-
3361
- This means that every secret in the .env file is encrypted with a unique AES-256 key, and that key is further encrypted using a public key (Secp256k1). Even if an attacker obtains the encrypted .env file, they would still need the corresponding private key—stored separately in a secrets manager—to decrypt anything.
3362
-
3363
- Breaking this encryption would require brute-forcing both AES-256 and elliptic curve cryptography, which is computationally infeasible with current technology. Read [the whitepaper](https://dotenvx.com/dotenvx.pdf?v=README) for more details.
3364
-
3365
- </details>
3366
- <details><summary>Why am I getting the error <code>node: .env: not found</code>?</summary><br>
3367
-
3368
- You are using Node 20 or greater and it adds a differing implementation of `--env-file` flag support. Rather than warn on a missing `.env` file (like dotenv has historically done), it raises an error: `node: .env: not found`.
3369
-
3370
- This fix is easy. Replace `--env-file` with `--file` (or `-f`).
3371
-
3372
- ```bash
3373
- # from this (legacy spelling):
3374
- ./node_modules/.bin/dotenvx run --env-file .env -- yourcommand
3375
- # to this:
3376
- ./node_modules/.bin/dotenvx run --file .env -- yourcommand
248
+ gh workflow run nodejs.yml --ref main -f target=core-beta -f publish=false
3377
249
  ```
3378
250
 
3379
- [more context](https://github.com/dotenvx/dotenvx/issues/131)
3380
-
3381
- </details>
3382
-
3383
- &nbsp;
251
+ The core test matrix installs the existing npm binaries and tests the actual
252
+ staged tarball, SDK imports, preload entry points, CLI dispatch, encryption, and
253
+ decryption. No Rust toolchain or native rebuild is used in core mode.
3384
254
 
3385
- ## Contributing
255
+ To publish or retry only the core beta, manually dispatch `nodejs.yml` from
256
+ `main`, choose `target=core-beta`, enable `publish`, and enter the exact version
257
+ from `dotenvx-nodejs/package.json` in the `version` input. Missing or mismatched
258
+ versions are rejected. Publication waits for the full core test matrix and uses
259
+ the `release` environment and GitHub OIDC, as do automatic tag releases.
260
+ The core package must trust
261
+ `dotenvx/forge`, workflow `nodejs.yml`, environment `release` on npm.
3386
262
 
3387
- You can fork this repo and create [pull requests](https://github.com/dotenvx/dotenvx/pulls) or if you have questions or feedback:
263
+ Only the validated `@dotenvx/dotenvx` tarball is published, with an explicit
264
+ `--tag next`, public npm registry, disabled lifecycle scripts, and disabled
265
+ provenance for this private repository. The publisher snapshots core/platform
266
+ tags, rechecks them before publication, and verifies them afterward. Only core's
267
+ `next` tag may change; `latest` and all platform tags must remain unchanged.
268
+ There is no stable-publish option, platform-publish command, or dist-tag mutation
269
+ command in the core publisher. Existing versions are never overwritten. An
270
+ identical retry is accepted only if the published integrity and `next` tag match.
3388
271
 
3389
- * [github.com/dotenvx/dotenvx](https://github.com/dotenvx/dotenvx/issues) - bugs and discussions
3390
- * [@dotenvx 𝕏](https://x.com/dotenvx) (DMs are open)
272
+ Both manual modes default to `publish=false`. A core beta can never be published
273
+ by pushing a branch or a `nodejs-v*` tag.