javascript - Reading a .config file -
currently have file called router.js set follows:
var server = require('mongodb').server; var mongodb = require('mongodb').db; var dbport = 31979; var dbhost = '40.117.155.19'; var dbname = 'node-login';
i to set this:
var server = require('mongodb').server; var mongodb = require('mongodb').db; var dbport = readconfig(dbport); var dbhost = readconfig(dbhost); var dbname = readconfig(dbname);
how go accomplishing this. have file such test.config, , able read dbport, dbhost, , dbname .config file in router.js.
you store config json file , read directly:
config.json
{ "dbport": 31979, "dbhost": "40.117.155.19", "dbname": "node-login" }
router.js
var server = require('mongodb').server; var mongodb = require('mongodb').db; var config = require('./config.json'); var dbport = config.dbport; var dbhost = config.dbhost; var dbname = config.dbname;
Comments
Post a Comment