Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature idea: support for .env.*.local by default #601

Closed
dscafati opened this issue Jun 22, 2021 · 4 comments
Closed

Feature idea: support for .env.*.local by default #601

dscafati opened this issue Jun 22, 2021 · 4 comments

Comments

@dscafati
Copy link

Hi, I want to propose this feature.

I see it's a common practice for frameworks to support multiple .env files by default, with specific order of precedence between them.

For example, a regular web app could contain

.env
.env.production
.env.development

The 3 files are versioned on git, and on each environment (local, prod, etc...) there's an extra *.local file. E.g.

.env.local
.env.production.local
.env.developoment.local

The order of precedence is

.env.{ENV}.local > .env.{ENV} > .env.local > .env

Example nextjs:
https://nextjs.org/docs/basic-features/environment-variables
https://github.com/vercel/next.js/blob/canary/packages/next-env/index.ts#L82

Example symfony:
https://symfony.com/doc/current/configuration.html#overriding-environment-values-via-env-local
https://github.com/symfony/symfony/blob/46ca50fd843b71ed5fc4517f5d87e04fdfb87768/src/Symfony/Component/Dotenv/Dotenv.php#L109

I'll be happy to implement this on the @nestjs/config package

@jmcdo29
Copy link
Member

jmcdo29 commented Jun 22, 2021

@dscafati
Copy link
Author

Hi @jmcdo29 thanks for your answer. I see I didn't make my point very clear. What I'm proposing here is to have this behavior by default. Coming from other frameworks I expected this to be the default behavior, not to have to define this myself

@dscafati dscafati changed the title Feature idea: support for .env.*.local Feature idea: support for .env.*.local by default Jun 22, 2021
@jmcdo29
Copy link
Member

jmcdo29 commented Jun 22, 2021

Hmm, personally I'd rather just keep .env as the default, as is the recommendation of the 12-factor app as I understand it, and allow for developers to define if they need extra functionality otherwise. I'm open to hear about the pros of allowing for this kind of configuration, but I generally follow a single .env if I can help it

@kamilmysliwiec
Copy link
Member

As @jmcdo29 pointed out above, this is already doable. The current default behavior mimics the underlying lib's behavior (dotenv) that we use for loading env vars. Currently, there're no plans to change this.

@nestjs nestjs locked and limited conversation to collaborators Jun 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants