node,返回require上的空对象

时间:2017-01-11 13:27:44

标签: javascript node.js

我的server.js文件:

let express = require('express'),
..
..
let server = express();

server.set('port', process.env.PORT || 3000);
..
server.set('isProduction',true);

let routes = require('./routes');

function routesSetup(server) {
  server.use('/api', routes);
}

function start(){
  ...
  console.log('app server up and running on 127.0.0.1:3000);
}

exports.start = start;
exports.server = server;

我的index.js文件,路径为routes/adduser/index.js

   let srv = require("../../server");
   console.log(srv.server.get('isProduction')) // cant read get of undefined...
   console.log(srv.server) // undefined
   console.log(srv) // {}

为什么srv是空对象?我需要访问服务器,以便检查server.js中的变量集

0 个答案:

没有答案