Skip to content

Commit

Permalink
Merge pull request #155 from Glavin001/patch-1
Browse files Browse the repository at this point in the history
Close #115. Add example code for overriding process.env to FAQ
  • Loading branch information
jcblw authored Oct 22, 2016
2 parents 6349be8 + ae0f81c commit 5f79fb0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ No. We **strongly** recommend against having a "main" `.env` file and an "enviro

We will never modify any environment variables that have already been set. In particular, if there is a variable in your `.env` file which collides with one that already exists in your environment, then that variable will be skipped. This behavior allows you to override all `.env` configurations with a machine-specific environment, although it is not recommended.

If you want to override `process.env` you can do something like this:

```javascript
const fs = require('fs')
const dotenv = require('dotenv')
const envConfig = dotenv.parse(fs.readFileSync('.env.override'))
for (var k in envConfig) {
process.env[k] = envConfig[k]
}
```


### Can I customize/write plugins for dotenv?

For `dotenv@2.x.x`: Yes. `dotenv.config()` now returns an object representing
Expand Down

0 comments on commit 5f79fb0

Please sign in to comment.