question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Possible to load multiple .env files into the shell?

See original GitHub issue

Question: Is it possible to load multiple .env files into the shell?

npx dotenv-extended --path=first.env dotenv-extended --path=second.env node herro.js

Or something like:

npx dotenv-extended --path=first.env,second.env node herro.js

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mvastolacommented, Jun 24, 2020

I was about to post this same feature request. The idea would be to allow for multiple layers of defaults/settings, as provided by dotenv-flow (which is fairly popular) as well as similar modules.

These other modules, however, aren’t easily made compatible with dotenv-extended, however, without allowing the overriding of values already in the environment. (Or otherwise by saving the original environment and re-applying it after the changes in this module.)

Implementing this feature a really simple change as well. The vast majority of the change is simply updating src/index.js to say

let envFiles = [];
[ options.defaults, options.path ].forEach(files => {
  if (!files || files.length === 0) return;
  if (!Array.isArray(files)) files = [ files ];
  envFiles.push(...files);
});
let configData = files.reduce((accumulator, file) => {
  let fileData = loadEnvironmentFile(file, options.encoding, options.silent);
  return { ...accumulator, ...fileData };
});

Beyond that, pretty much only CLI argument parsing would need to be tweaked, and documentation would need to be updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cleaner Way to load multiple environment variables into shell
I would use source ( . ) command with process substitution: . <(grep -e '^VAR_1=' -e '^VAR_2=' .env). or . <(grep '^VAR_[12]=' .env)...
Read more >
Using several .env files within my app (general and testing)
Hi, my question is related with the .env files. Is possible to have multiple .env files within the same application? How to know...
Read more >
Using multiple .env files. - Prisma
One solution is to have multiple .env files which each represent different environments. In practice this means you create a file for each...
Read more >
How To Use .env Variables In package.json - GenUI
It's common to need access to your environment variables in multiple places. Your code, your build scripts, and your pipeline may all need...
Read more >
Environment variables in Expo
This approach this plugin will work well with environment variables set in your shell process, but it won't automatically load .env files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found