-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add .env support. * Handle promise rejection. * Use process.env.DOTENV * Use dotenv * Use dotenv module * Move env loading to a util, copy to workers, add tests
- Loading branch information
1 parent
065a49e
commit 50de97f
Showing
8 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const config = require('./config'); | ||
const dotenv = require('dotenv'); | ||
|
||
async function loadEnv(filepath) { | ||
const NODE_ENV = process.env.NODE_ENV || 'development'; | ||
const dotenvFiles = [ | ||
`.env.${NODE_ENV}.local`, | ||
`.env.${NODE_ENV}`, | ||
// Don't include `.env.local` for `test` environment | ||
// since normally you expect tests to produce the same | ||
// results for everyone | ||
NODE_ENV !== 'test' && '.env.local', | ||
'.env' | ||
].filter(Boolean); | ||
|
||
await Promise.all( | ||
dotenvFiles.map(async dotenvFile => { | ||
const envPath = await config.resolve(filepath, [dotenvFile]); | ||
if (envPath) { | ||
dotenv.config({path: envPath}); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
module.exports = loadEnv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FOO=bar | ||
BAR=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = process.env.FOO + process.env.BAR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters