-
Notifications
You must be signed in to change notification settings - Fork 255
feat: add env prefix option #428
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
Conversation
Hi @indexzero, just wanted to kindly follow up on this PR to see if there’s anything else I can do to help move it forward? Thank you :) |
Hi @mhamann, just wanted to kindly follow up on this PR to see if there’s anything else I can do to help move it forward? Thank you :) |
Hey @dderevjanik, thanks for your submission. Seems like a good feature that adds some parity with libraries in other languages. I'll go ahead and merge it, but it may take a bit of time to get it released due to my current workload. |
@mhamann thanks for merging this enhancement and for the nconf library in general would it be possible to publish a new release of nconf to npm to make this feature available for import? |
I'll try to get this released by end of week. Thanks! |
Thanks again @mhamann I appreciate the work you have and continue to put in on this module. Incidentally, as may already be obvious to some in this thread, I realized that one can emulate this prefix-stripping (and the corresponding "ignore everything without the prefix) behavior by adding a transform to the env() options map. E.g. something like this: // the prefix to strip from env var keys; e.g., `foo_bar` -> `bar`
const envVarPrefix = "foo_";
// when true, only include env vars that start with the prefix
const excludeWhenMissingPrefix = true;
const envOptions = {
transform: (pair: { key: string, value: unknown }): { key: string, value: unknown } | null => {
if (pair.key.startsWith(envVarPrefix)) {
pair.key = pair.key.substring(envVarPrefix.length);
return pair;
} else {
return excludeWhenMissingPrefix ? null : pair;
}
}
}
nconf.env(envOptions); This |
@rodw You're absolutely right that the const envOptions = {
prefix: "foo_",
separator: "__",
parseValues: true
};
nconf.env(envOptions); With this PR, the This approach keeps the configuration clean and declarative while avoiding the need for a custom |
Hi @mhamann, Just checking in, do you have any plans to make a new release that includes this feature? Thanks in advance! :) |
* feat: add env prefix option * chore: remove console.log from test
This is now released in |
Hmm, interesting. All of the tests pass. Are we missing coverage there? |
This pull request introduces a new feature to env store
prefix
, allowing environment variables to be filtered and stripped of a specified prefix.ref #157
based on https://www.dynaconf.com/envvars/