Replies: 3 comments
-
|
One of us needs to build a POC that we can import node-config from within the config directory. The full examples I currently have do not work, but that could be due to other factors. If that doesnβt work then we need some way to feed defer() into the scope of the mjs files. Thereβs a terrible hack for doing this in CJS modules but no equivalent for ESM |
Beta Was this translation helpful? Give feedback.
-
|
For the record, I don't like this idea. But I also am not aware of any other solutions to some of the problems I believe I'm seeing in #841 I'd like to build a bare minimum test of the patterns we are using to make sure that the problems are specific to NodeJS and not something we can control internally. However things are not looking great at the moment for a single-module solution for some of these backlog items. |
Beta Was this translation helpful? Give feedback.
-
|
There's a way out of this mess once we hit 5.0 and get ESM support. We can expose the singleton as the default export and Config as an explicit export. Possibly Util and friends as well. Also the problem of having to import node-config while it's still loading can be fixed with #863, where we surface only the parts of node-config that we intend to support running as reentrant code (which is at this moment, Util, Load, and defer) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
A what-if conversation.
What if node-config was split into two, with an inner module that I call "libconfig" here with node-config being a wrapper.
libconfig would:
It would be a class with a constructor to which you can pass all the arguments to support all the features that node-config needs. It would then return a config object appropriately configured.
node-configcould call it, get a config object back and set up its singletons and environment variables to behave as it does now.A large, corporate code-base might call libconfig directly to set up config just how they like it and setup their own singleton, where the rest of the code base would access it as
../service/Config, but this would not interfere with other uses by submodules.The solution would allow users to solve some pain-points they have that are not likely to be changed in
node-configwould be reasonable withlibconfig. For example.localfor local overrides. This could be an option to the constructor.Where's the boundary?
There would have be some decisions about where the boundary is between what's in the interior "lib" what's what's not.
For example, would the library continue to read "custom-environment-variables.json" or would it instead take "customEnvVars" as as a constructor option? If the later, it would open the door to storing this mapping in non-JSON formats.
Config'ing the config system.
If the config library would have several options to configure, this begs the question, how to configure the config system?
The answer with NODE_CONFIG has been with up to 10 environment variables. But even those don't hold all the options users might want, like specifying which formats we include or exclude or exclude and handling "local" files.
One recommended pattern could be to use a wrapper class that calls the constructor with the preferred options and returns something useful. Depending on the need, maybe it's a singleton or maybe it's not. After that, on the original env vars would likely be needed: NODE_ENV and and NODE_APP_INSTANCE.
Future
After the split, I would expect that development on the outer wrapper known as node-config would be largely maintenance only. New users would recommended to use the library with more explicit configuration instead.
Design
I expect the new library would be written in TypeScript and would have a nice tooling experience so as you creating a new constructor in your editor, you are able to see what the options are right there and what their docs here.
The docs could provide some examples that cover typical cases.
Beta Was this translation helpful? Give feedback.
All reactions