Reading a .config file

后端 未结 2 1989
天命终不由人
天命终不由人 2021-02-04 04:16

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;
         


        
2条回答
  •  无人共我
    2021-02-04 04:45

    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;
    

提交回复
热议问题