dimanche 19 avril 2015

Attaching object to Node.js process

I am using the environment variable and arguments parsing module called nconf for my node.js Express web server.


http://ift.tt/1G8l3EY


I decided that the best way to make the nconf data global was to simply attach it to the process variable (as in process.env), is this a good idea or bad idea? Will it slow down execution in weighing down "process"?


Here is my code:



var nconf = require('nconf');

nconf.argv()
.env()
.file({ file: './config/config.json' });

nconf.defaults({
'http': {
'port': 3000
}
});

process.nconf = nconf;

//now I can retrieve config settings anywhere like so process.nconf.get('key');


frankly, I kind of like this solution. Now I can retrieve the config data anywhere, without having to require a module. But there may be downsides to this...and it could quite possibly be a very bad idea. IDK.


Aucun commentaire:

Enregistrer un commentaire