Skip to content

Commit 5861f6a

Browse files
committed
Add failing test demonstrating need for DOTENV_KEY option
1 parent 4f48954 commit 5861f6a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ console.log(myObject) // values from .env or .env.vault live here now.
339339
console.log(process.env) // this was not changed or written to
340340
```
341341

342+
##### DOTENV_KEY
343+
344+
Default: `process.env.DOTENV_KEY`
345+
346+
Pass the `DOTENV_KEY` directly to config options. Defaults to looking for `process.env.DOTENV_KEY` environment variable. Note this only applies to decrypting `.env.vault` files. If passed as null or undefined, or not passed at all, dotenv falls back to its traditional job of parsing a `.env` file.
347+
348+
```js
349+
require('dotenv').config({ DOTENV_KEY: 'dotenv://:key_1234…@dotenv.org/vault/.env.vault?environment=production' })
350+
```
351+
342352
### Parse
343353

344354
The engine which parses the contents of your file containing environment

tests/test-config-vault.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ t.test('when DOTENV_KEY is empty string falls back to .env file', ct => {
170170
ct.end()
171171
})
172172

173+
t.test('when DOTENV_KEY is passed as an option it successfully decrypts and injects', ct => {
174+
envStub.restore()
175+
envStub = sinon.stub(process.env, 'DOTENV_KEY').value('')
176+
177+
ct.plan(1)
178+
179+
const result = dotenv.config({ path: testPath, DOTENV_KEY: dotenvKey })
180+
181+
ct.equal(result.parsed.ALPHA, 'zeta')
182+
ct.equal(process.env.ALPHA, 'bar')
183+
184+
ct.end()
185+
})
186+
173187
t.test('does not write over keys already in process.env by default', ct => {
174188
ct.plan(2)
175189

0 commit comments

Comments
 (0)