Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,33 @@

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/v17.1.0...master)
## [Unreleased](https://github.com/motdotla/dotenv/compare/v17.2.0...master)

## [17.2.0](https://github.com/motdotla/dotenv/compare/v17.1.0...v17.2.0) (2025-07-09)

### Added

* Optionally specify `DOTENV_CONFIG_QUIET=true` in your environment or `.env` file to quiet the runtime log ([#889](https://github.com/motdotla/dotenv/pull/889))
* Just like dotenv any `DOTENV_CONFIG_` environment variables take precedence over any code set options like `({quiet: false})`

```ini
# .env
DOTENV_CONFIG_QUIET=true
HELLO="World"
```
```js
// index.js
require('dotenv').config()
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
Hello World

or

$ DOTENV_CONFIG_QUIET=true node index.js
```

## [17.1.0](https://github.com/motdotla/dotenv/compare/v17.0.1...v17.1.0) (2025-07-07)

Expand Down
28 changes: 19 additions & 9 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ function _getRandomTip () {
return TIPS[Math.floor(Math.random() * TIPS.length)]
}

function parseBoolean (value) {
if (typeof value === 'string') {
return !['false', '0', 'no', 'off', ''].includes(value.toLowerCase())
}
return Boolean(value)
}

function supportsAnsi () {
return process.stdout.isTTY // && process.env.TERM !== 'dumb'
}
Expand Down Expand Up @@ -216,8 +223,8 @@ function _resolveHome (envPath) {
}

function _configVault (options) {
const debug = Boolean(options && options.debug)
const quiet = Boolean(options && options.quiet)
const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || (options && options.debug))
const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || (options && options.quiet))

if (debug || !quiet) {
_log('Loading env from encrypted .env.vault')
Expand All @@ -238,8 +245,12 @@ function _configVault (options) {
function configDotenv (options) {
const dotenvPath = path.resolve(process.cwd(), '.env')
let encoding = 'utf8'
const debug = Boolean(options && options.debug)
const quiet = Boolean(options && options.quiet)
let processEnv = process.env
if (options && options.processEnv != null) {
processEnv = options.processEnv
}
let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || (options && options.debug))
let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || (options && options.quiet))

if (options && options.encoding) {
encoding = options.encoding
Expand Down Expand Up @@ -279,13 +290,12 @@ function configDotenv (options) {
}
}

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

const populated = DotenvModule.populate(processEnv, parsedAll, options)

// handle user settings DOTENV_CONFIG_ options inside .env file(s)
debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug)
quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet)

if (debug || !quiet) {
const keysCount = Object.keys(populated).length
const shortPaths = []
Expand Down
74 changes: 11 additions & 63 deletions tests/test-config-vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,6 @@ t.afterEach(() => {
}
})

t.test('logs when no path is set', ct => {
ct.plan(1)

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

dotenv.config()
ct.ok(logStub.called)
})

t.test('does log by default', ct => {
ct.plan(1)

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

dotenv.config({ path: testPath })
ct.ok(logStub.called)
})

t.test('does not log if quiet flag passed true', ct => {
ct.plan(1)

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

dotenv.config({ path: testPath, quiet: true })
ct.ok(logStub.notCalled)
})

t.test('does log if quiet flag false', ct => {
ct.plan(1)

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

dotenv.config({ path: testPath, quiet: false })
ct.ok(logStub.called)
})

t.test('does log if quiet flag present and undefined/null', ct => {
ct.plan(1)

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

dotenv.config({ path: testPath, quiet: undefined })
ct.ok(logStub.called)
})

t.test('logs if debug set', ct => {
ct.plan(1)

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

dotenv.config({ path: testPath, debug: true })
ct.ok(logStub.called)
})

t.test('does log when testPath calls to .env.vault directly (interpret what the user meant)', ct => {
ct.plan(1)

Expand All @@ -88,18 +34,10 @@ t.test('does log when testPath calls to .env.vault directly (interpret what the
ct.ok(logStub.called)
})

t.test('logs when testPath calls to .env.vault directly (interpret what the user meant) and debug true', ct => {
ct.plan(1)

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

dotenv.config({ path: `${testPath}.vault`, debug: true })
ct.ok(logStub.called)
})

t.test('warns if DOTENV_KEY exists but .env.vault does not exist', ct => {
ct.plan(1)

const testPath = 'tests/.env'
logStub = sinon.stub(console, 'log')

const existsSync = sinon.stub(fs, 'existsSync').returns(false) // make .env.vault not exist
Expand All @@ -113,6 +51,7 @@ t.test('warns if DOTENV_KEY exists but .env.vault does not exist', ct => {
t.test('warns if DOTENV_KEY exists but .env.vault does not exist (set as array)', ct => {
ct.plan(1)

const testPath = 'tests/.env'
logStub = sinon.stub(console, 'log')

const existsSync = sinon.stub(fs, 'existsSync').returns(false) // make .env.vault not exist
Expand All @@ -123,6 +62,15 @@ t.test('warns if DOTENV_KEY exists but .env.vault does not exist (set as array)'
ct.end()
})

t.test('logs when testPath calls to .env.vault directly (interpret what the user meant) and debug true', ct => {
ct.plan(1)

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

dotenv.config({ path: `${testPath}.vault`, debug: true })
ct.ok(logStub.called)
})

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

Expand Down
Loading