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

URLSearchParams to split process.env variables #1730

Open
dbauszus-glx opened this issue Nov 19, 2024 · 5 comments · May be fixed by #1796
Open

URLSearchParams to split process.env variables #1730

dbauszus-glx opened this issue Nov 19, 2024 · 5 comments · May be fixed by #1796
Assignees
Labels
Code Issues related to the code structure and performance.

Comments

@dbauszus-glx
Copy link
Member

Where multiple process.env variables are required to support a single module it would be advantageous to provide a single environment variable which can split with URLSearchParams.

This could be applied for SAML2, Mailer [TRANSPORT], dbs, and possibly more.

Object.fromEntries(new URLSearchParams(process.env.DBS).entries())
@dbauszus-glx dbauszus-glx added the Code Issues related to the code structure and performance. label Nov 19, 2024
@cityremade cityremade self-assigned this Jan 6, 2025
@dbauszus-glx
Copy link
Member Author

Having a config/env module for the process.env variables may help with transofrmations, defaults, and documentation as well.

https://www.youtube.com/watch?v=kgiwKbKcSyk

@cityremade cityremade linked a pull request Jan 6, 2025 that will close this issue
@RobAndrewHurst
Copy link
Contributor

RobAndrewHurst commented Jan 6, 2025

Having a config/env module for the process.env variables may help with transofrmations, defaults, and documentation as well.

https://www.youtube.com/watch?v=kgiwKbKcSyk

image

This kind of thing is already built into dotenv.

@RobAndrewHurst
Copy link
Contributor

RobAndrewHurst commented Jan 6, 2025

Where multiple process.env variables are required to support a single module it would be advantageous to provide a single environment variable which can split with URLSearchParams.

This could be applied for SAML2, Mailer [TRANSPORT], dbs, and possibly more.

Object.fromEntries(new URLSearchParams(process.env.DBS).entries())

Also this needs more clarification. Are we talking about (as an example) a single string that has all the different possible DB_* entries?

@RobAndrewHurst
Copy link
Contributor

https://github.com/dotenvx/dotenvx

I think the route of a single entry for module doesn't quite make sense to be as it will quite hard to read when configuring/debugging.

I think we should possibly make use of a package like the new dotenvx which we can use to combine multiple .env files which we can use to split up different module .env variables.

As for getting all the different variables that we would need for a module we should just be able to provide a prefix and get them from the process.

const getEnvsByPrefix = (prefix) => {
  return Object.keys(process.env)
    .filter(key => key.startsWith(prefix))
    .reduce((obj, key) => ({
      ...obj,
      [key]: process.env[key]
    }), {});
};

Something like this would be ideal where we could provide DB_ to the function and get all the keys returned.

@cityremade
Copy link
Member

cityremade commented Jan 7, 2025

more complex functions on variables can be implemented in the configuration module.
That way we can have all in one place.
For now I've only used iteration on process.env values but surely there are lost of possibilities to expand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Issues related to the code structure and performance.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants