Tuesday 23 May 2017

Nconf - when to use load()

It is the first time I have tried a config manager and I found the methods a little bit confusing.

nconf.file('global', './config.json');
nconf.load();
console.log(nconf.get('google_api_key'));

Above is just some code that I was using for testing. I could not understand the use of load() method. Even if I don't use the load method, I still get the config contents correctly printed out.

Here is what the documentation says about the method:

Based on the Memory store, but provides additional methods .save() and .load() which allow you to read your configuration to and from the file. As with the Memory store, all method calls are synchronous with the exception of .save() and .load() which take callback functions.

In what cases do we use the load() method and is it actually needed while reading values from the config file?



via Himanshu Jain

No comments:

Post a Comment