Randy Song Randy Song - 1 year ago 230
Node.js Question

Can't load configuration json file using nconf

I'm trying to follow the example here:

What I'm trying to do is load a configuration json file using nconf, but I can't seem to actually retrieve any of the configs. I've exported this to another file, but I've also tried just running this file directly too. I have:

var config = require('nconf');
//priority order
//1. specific overrides
'always': 'be this value'

//2. process.argv
//3. process.env

config.file('development', 'development.json');

module.exports = config;

Yet the output is always undefined. my json is defined as such:

"nodeServer": "http://localhost:8090",
"port": 8090

and it's in the same directory as config.js. Any idea why this is occurring?

Also want to note, in my main server.js I have:

var config = require('./config/config');

and that also returns undefined.

Answer Source

Turns out that I just needed this:

    {file: 'config/development.json'});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download