Skip to content

Commit

Permalink
Update CHANGELOG and README
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Jun 16, 2023
1 parent 96c29b4 commit 431521d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 13 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,10 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [Unreleased](https://github.com/motdotla/dotenv/compare/v16.1.0...master)
## [Unreleased](https://github.com/motdotla/dotenv/compare/v16.2.0...master)

## [16.2.0](https://github.com/motdotla/dotenv/compare/v16.1.4...v16.2.0) (2023-06-15)

### Added

- Optionally write to your own target object rather than `process.env`. Defaults to `process.env`. [#753](https://github.com/motdotla/dotenv/pull/753)
- Add import type URL to types file [#751](https://github.com/motdotla/dotenv/pull/751)

## [16.1.4](https://github.com/motdotla/dotenv/compare/v16.1.3...v16.1.4) (2023-06-04)
Expand Down
37 changes: 33 additions & 4 deletions README.md
Expand Up @@ -283,7 +283,7 @@ You can additionally, pass options to `config`.

#### Options

##### Path
##### path

Default: `path.resolve(process.cwd(), '.env')`

Expand All @@ -293,7 +293,7 @@ Specify a custom path if your file containing environment variables is located e
require('dotenv').config({ path: '/custom/path/to/.env' })
```

##### Encoding
##### encoding

Default: `utf8`

Expand All @@ -303,7 +303,7 @@ Specify the encoding of your file containing environment variables.
require('dotenv').config({ encoding: 'latin1' })
```

##### Debug
##### debug

Default: `false`

Expand All @@ -313,7 +313,7 @@ Turn on logging to help debug why certain keys or values are not being set as yo
require('dotenv').config({ debug: process.env.DEBUG })
```

##### Override
##### override

Default: `false`

Expand All @@ -323,6 +323,19 @@ Override any environment variables that have already been set on your machine wi
require('dotenv').config({ override: true })
```

##### processEnv

Default: `process.env`

Specify an object to write your secrets to. Defaults to `process.env` environment variables.

```js
const myObject = {}
require('dotenv').config({ processEnv: myObject })

// myObject will receive the values from your .env file rather than process.env
```

### Parse

The engine which parses the contents of your file containing environment
Expand Down Expand Up @@ -393,6 +406,22 @@ Default: `false`

Override any environment variables that have already been set.

### Decrypt

The engine which decrypts the ciphertext contents of your .env.vault file is available for use. It accepts a ciphertext and a decryption key. It uses AES-256-GCM encryption.

For example, decrypting a simple ciphertext:

```js
const dotenv = require('dotenv')
const ciphertext = 's7NYXa809k/bVSPwIAmJhPJmEGTtU0hG58hOZy7I0ix6y5HP8LsHBsZCYC/gw5DDFy5DgOcyd18R'
const decryptionKey = 'ddcaa26504cd70a6fef9801901c3981538563a1767c297cb8416e8a38c62fe00'

const decrypted = dotenv.decrypt(ciphertext, decryptionKey)

console.log(decrypted) // # development@v6\nALPHA="zeta"
```

## ❓ FAQ

### Why is the `.env` file not loading my environment variables successfully?
Expand Down
12 changes: 4 additions & 8 deletions lib/main.js
Expand Up @@ -163,10 +163,8 @@ function _configVault (options) {
const parsed = DotenvModule._parseVault(options)

let processEnv = process.env
if (options) {
if (options.processEnv != null) {
processEnv = options.processEnv
}
if (options && options.processEnv != null) {
processEnv = options.processEnv
}

DotenvModule.populate(processEnv, parsed, options)
Expand All @@ -193,10 +191,8 @@ function configDotenv (options) {
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }))

let processEnv = process.env
if (options) {
if (options.processEnv != null) {
processEnv = options.processEnv
}
if (options && options.processEnv != null) {
processEnv = options.processEnv
}

DotenvModule.populate(processEnv, parsed, options)
Expand Down
15 changes: 15 additions & 0 deletions tests/test-config-vault.js
Expand Up @@ -194,6 +194,21 @@ t.test('does write over keys already in process.env if override turned on', ct =
ct.equal(process.env.ALPHA, 'zeta')
})

t.test('can write to a different object rather than process.env', ct => {
ct.plan(3)

process.env.ALPHA = 'other' // reset process.env

logStub = sinon.stub(console, 'log')

const myObject = {}

const result = dotenv.config({ path: testPath, processEnv: myObject })
ct.equal(result.parsed.ALPHA, 'zeta')
ct.equal(process.env.ALPHA, 'other')
ct.equal(myObject.ALPHA, 'zeta')
})

t.test('logs when debug and override are turned on', ct => {
ct.plan(1)

Expand Down
14 changes: 14 additions & 0 deletions tests/test-config.js
Expand Up @@ -135,6 +135,20 @@ t.test(
}
)

t.test('can write to a different object rather than process.env', ct => {
ct.plan(3)

process.env.test = 'other' // reset process.env

const myObject = {}
const env = dotenv.config({ processEnv: myObject })

ct.equal(env.parsed && env.parsed.test, mockParseResponse.test)
console.log('logging', process.env.test)
ct.equal(process.env.test, 'other')
ct.equal(myObject.test, mockParseResponse.test)
})

t.test('returns parsed object', ct => {
ct.plan(2)

Expand Down

0 comments on commit 431521d

Please sign in to comment.