env-cmd
env-cmd copied to clipboard
Variables from multiple .env files
Hey!
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
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 😄
We fixed it in a way by using: env-cmd -f .env.staging env-cmd -f .env.staging.local --silent run-scripts build
Because of silent it doesn't matter if you have a local file, but it will be read.
Is there any progress?
It seems that the PR of related functions was merged before, why is the newer version deleted? Related PR: https://github.com/toddbluhm/env-cmd/pull/17
Another use for this is to put project specific variables (such as queue or data source names) in the project, but keep things like AWS tokens in a separate file that is not commit'd.
Shame env-cmd doesn't support this, because otherwise it works well
Hi. Any plans for this issue? Is this project still maintained or is there a newer alternative?
I can't pass more than one .env.*
files with just env-cmd -f .env.file1 -f .env.file2
?
It is necessary to implement this functionality
Workaround that seemed to work for me:
env-cmd -f .env1 env-cmd -f .env2 my_command
you can use dotenvx
for this
# .env
HELLO="World"
# .env.local
HELLO="Local"
// index.js
console.log(`Hello ${process.env.HELLO}`)
dotenvx run --env-file=.env.local --env-file=.env -- node index.js