On Jun 3, 2014, at 1:41 PM, Tony Barbieri <[email protected]> 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?  

I prefer the latter by far — more like a constructor. You can always do 
something like this:

var library = require(‘mylib’).create(require(‘./config.json’)).


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to