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

✨ Increased transparency by always using env var names #52

Open
smoliji opened this issue Jan 20, 2025 · 0 comments
Open

✨ Increased transparency by always using env var names #52

smoliji opened this issue Jan 20, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@smoliji
Copy link
Contributor

smoliji commented Jan 20, 2025

Is your feature request related to a problem?

No.

What feature would you like to see?

I'd like to use env vars name directly like so, e.g.: config.SERVER_PORT without having to map it to arbitrary config object, obstructing the name which is then accessible under a different name, e.g. config.server.port.

This change would...

  • make it easier to found all the usages of a environment variable
  • make life easier without having to worry too much about the config object structure (additional layer of naming, nesting..)
  • prevent misusing the config object structure (it is not defined and every developer may understand it differently)

What alternatives have you considered?

Composing the config object the same way as the environment variable name, e.g.

config = {
  SERVER_PORT: loader.number('SERVER_PORT')
}

but then I find it unnecessary, still prone to typos and I believe this could be done automatically. The only thing it needs is to keep type safety.

Alternative idea for defining the config by following Record<string, Loader>:

config = {
   SERVER_PORT: loader.number(),
}

Another idea could be to generate such config file automatically from .env.jsonc, which could nicely work with the descriptions there, but it would make it harder to select appropriate loader, and even harder with customer loaders (But I would sacrifice the customer loaders altogether, I believe such code that needs additional transformation of the config belongs in application logic, not config loader, but that's a different topic)

Additional context

No response

@smoliji smoliji added the enhancement New feature or request label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant