Variables from multiple .env files
See original GitHub issueHey!
Thanks for the awesome lib!
It would be nice if env-cmd could read variables from multiple .env files. There is a common approach to use .env and .env.local, and maybe .env.<environment> (.env.production, .env.development, etc.) schema.
Here are the examples:
- https://symfony.com/doc/current/configuration.html#overriding-environment-values-via-env-local (Symfony)
- https://nextjs.org/docs/basic-features/environment-variables#default-environment-variables (Next.js)
- https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used (Create React App)
It’s a common and nice practice since you can use common defaults in an .env file and then override them in a machine-specific .env.local. Usually you commit .env to a git repository and do not commit .env.local (secrets go there).
Currently it looks like it’s impossible to use env-cmd in such way. It would be nice if we could by using some argument, for example:
env-cmd --cascade mocha -R spec
# or different argument name of course
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:7 (1 by maintainers)
Top Results From Across the Web
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 >Loading Multiple .env Files for Different Environments in NodeJS
The most natural solution is to have two different .env files - one for each environment. Let's name the first .env.dev for the...
Read more >Toggle between multiple .env files like .env.development with ...
When working on my vue.js projects, I can use files like .env.development or .env.production to get different values for the same env key ......
Read more >Node JS Environment Variables — Setting Node app for ...
Configuring environment variables to a separate file rather than in our node js code enables us to run and point our app to...
Read more >Managing multiple environment file in NodeJS - Dev Genius
My approach was to create only one . env file and write down all variable files in it.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

We fixed it in a way by using:
env-cmd -f .env.staging env-cmd -f .env.staging.local --silent run-scripts buildBecause of silent it doesn’t matter if you have a local file, but it will be read.I had been thinking about this idea for a while. Probably the next major rewrite will take this approach. Not sure when that will be, but I have been needing to turn my attention back to this project for a while now. Thanks for the feature request 😄