Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set dotenv_config_* vars via env var #354

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -65,6 +65,9 @@ The configuration options below are supported as command line arguments in the f
$ node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/your/env/vars
```

If you are having trouble passing the `dotenv_config_<option>=value` part via the CLI, you can use environment variables instead. When using environment variables, be sure to use uppercase names, `DOTENV_CONFIG_<OPTION>=value`.


## Config

_Alias: `load`_
Expand Down
2 changes: 1 addition & 1 deletion config.js
Expand Up @@ -2,6 +2,6 @@

(function () {
require('./lib/main').config(
require('./lib/cli-options')(process.argv)
Object.assign({}, require('./lib/env-options')(process.env), require('./lib/cli-options')(process.argv))
)
})()
9 changes: 9 additions & 0 deletions lib/env-options.js
@@ -0,0 +1,9 @@
/* @flow */

module.exports = function (env = {}) {
return Object.assign({},
env.DOTENV_CONFIG_ENCODING ? { encoding: env.DOTENV_CONFIG_ENCODING } : null,
env.DOTENV_CONFIG_PATH ? { path: env.DOTENV_CONFIG_PATH } : null,
env.DOTENV_CONFIG_DEBUG ? { debug: env.DOTENV_CONFIG_DEBUG } : null
)
}
29 changes: 29 additions & 0 deletions tests/test-env-options.js
@@ -0,0 +1,29 @@
/* @flow */

const t = require('tap')

const options = require('../lib/env-options')

t.plan(6)

// matches encoding option
t.same(options({ DOTENV_CONFIG_ENCODING: 'utf8' }), {
encoding: 'utf8'
})

// matches path option
t.same(options({ DOTENV_CONFIG_PATH: '/custom/path/to/your/env/vars' }), {
path: '/custom/path/to/your/env/vars'
})

// matches debug option
t.same(options({ DOTENV_CONFIG_DEBUG: 'true' }), {
debug: 'true'
})

// ignores empty values
t.same(options(), {})
t.same(options({}), {})

// ignores unsupported options
t.same(options({ DOTENV_CONFIG_FOO: 'foo' }), {})