Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Use the following properties to configure your instance.
* **defaults** (`false`) - Adds support for `dotenv-defaults`. If set to `true`, uses `./.env.defaults`. If a string, uses that location for a defaults file. Read more at [npm](https://www.npmjs.com/package/dotenv-defaults).
* **ignoreStub** (`false`) - Override the automatic check whether to stub `process.env`. [Read more here](#user-content-processenv-stubbing--replacing).
* **prefix** (`'process.env.'`) - The prefix to use before the name of your env variables.
* **force** (`false`) - This will override existing env variables with anything you pass in from your file.

The following example shows how to set any/all arguments.

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Dotenv {
const { env, blueprint } = this.getEnvs()

Object.keys(blueprint).forEach(key => {
const value = Object.prototype.hasOwnProperty.call(vars, key) ? vars[key] : env[key]
const value = !this.config.force && Object.prototype.hasOwnProperty.call(vars, key) ? vars[key] : env[key]

const isMissing = typeof value === 'undefined' || value === null ||
(!allowEmptyValues && value === '')
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ describe.each(versions)('%s', (_, DotenvPlugin) => {
})
})

describe('force configuration', () => {
test('Should override if forced', (done) => {
expectResultsToContainReplacements(
new DotenvPlugin({ force: true }),
{ ...defaultEnvResult, ...missingOneResult },
done
)
})
})

describe('Defaults configuration', () => {
test('should support default configurations', (done) => {
expectResultsToContainReplacements(
Expand Down