vscode-restclient icon indicating copy to clipboard operation
vscode-restclient copied to clipboard

Allow for a dotenv per environment

Open elpablete opened this issue 5 years ago • 4 comments

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)

elpablete avatar Dec 29 '20 02:12 elpablete

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.

philwrenn avatar Jan 17 '21 01:01 philwrenn

usually such files are named like so

.env
.env.local
.env.production

FDiskas avatar Mar 31 '21 10:03 FDiskas

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.

wekempf avatar Nov 05 '21 21:11 wekempf

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 ?

monisnap-paul avatar Mar 11 '22 14:03 monisnap-paul

I would love to have this feature too! Maintainers, could you please review and merge the PR mentioned here?

Nilegfx avatar Jun 21 '23 12:06 Nilegfx