Reading A .config File
Currently I have a file called router.js set up as follows: var Server = require('mongodb').Server; var MongoDB = require('mongodb').Db; var dbPort = 31979; var dbHost = '40.117.15
Solution 1:
You could store your config as a JSON file and read it 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;
Solution 2:
Here's one way to do it
//File config.js
module.exports = {
dbPort : 8080,
dbHost : etc,
dbName : nom,
}
//File server.js
var Server = require('mongodb').Server;
var MongoDB = require('mongodb').Db;
var config = require('configFile');
var dbPort = config.dbPort;
var dbHost = config.dbHost;
var dbName = config.dbName;
Post a Comment for "Reading A .config File"