Allow for a dotenv per environment
Many times I find myself with an .env file per environment (local.env, test.env, prod.env), that way I can use the same names on my code and still not commit any values to repos. Right now there is no way to do so, but a more powerful feature would be to allow a different .env file to be defined in each environment (even in $shared)
Something like this would be helpful for me too. I'm not currently using different .env files, but I would like to store a few .http files in a folder. That would mean they wouldn't be in the project root with my .env file.
If we could provide a relative path to a specific .env file, then @elpablete and my issue would possibly both be addressed.
usually such files are named like so
.env
.env.local
.env.production
I'd love this as well, but until (if?) this is done, there's a workaround. In your settings.json you define your environments like this.
"dev":
{
"secret": "devSecret"
},
"prod":
{
"secret": "prodSecret"
}
In your .env file you'd then have this.
devSecret=xyzzy
prodSecret=plough
Finally in your http file you'd have this.
@secret = {{$dotenv %secret}}
A little more complicated to setup, but this allows the values you use to change when you change the environment. This is untested and may need some tweaking, but the idea should work.
Would it be possible to try to load first .env.{{environmentName}} with environmentName the name of the currentEnvironment (e.g. .env.local, env.dev, ...) and if this file does exist, load the .env file in $dotenv variable ?
I would love to have this feature too! Maintainers, could you please review and merge the PR mentioned here?