When you "require" a module, you have no control over the life time of the 
instance returned. You get the instance across the entire process. This is a 
big problem for testing. Approach two enables pushing in different 
configuration under different circumstances. At times, I've needed other 
modules to be pushed in rather than "required" directly. 

Consider how you would tackle this problem if you were publishing the module as 
an NPM package from its own repository. You wouldn't assume that a client of 
the module would place a configuration file in some common place. You likely 
wouldn't impose a service configuration mechanism on the dev using your module.

Obviously, it depends. Sometimes simply requiring a config Json file directly 
is more than good enough. 

Mario Pareja


On Tuesday, 3 June 2014 21:03:42 UTC-4, Tony Barbieri  wrote:
> Hello!
> 
> 
> I'm writing a library that will be used as a submodule and I would like to 
> allow developers to setup configuration for it.  A few of these config 
> options would be setting defaults for server url, login and password.  
> 
> 
> 
> Is there already a pattern for dealing with this situation?  I imagine it 
> could be done a couple of ways:
> 
> 
> The submodule will always look for a config at some "hard-coded" location in 
> the app hierarchy i.e. {app}/config/{submodule.config}?  Using this method, 
> what is the best way for the submodule to find that location relative to the 
> running application at run time?
> Provide a function as part of my exports that allows the developer to load a 
> config from any location at run time.  Given this technique, maybe a config 
> file is unnecessary and the config settings should just be set using 
> javascript rather than loading a file.
> 
> Should both methods be used?  Are there other options or patterns that are 
> common?  
> 
> 
> Any help is much appreciated!
> 
> -- 
> Tony

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/5bd88768-a51d-4fa3-8284-248c69996768%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to