在另一个路由器nodejs中需要相同的模块实例

时间:2017-08-31 07:30:52

标签: javascript node.js

server.js中的

const sql = require('mssql');

const getSqlInstance = () => {
    return sql
}

module.exports = {
    getSqlInstance
}

在database.js中

const sql = require('../../server').getSqlInstance();

为什么会抛出require(...).getSqlInstance is not a function错误?我该如何解决这个问题?

文件夹结构

root
  -- routes
    --api
      --database.js
  --server.js


TypeError: require(...).getSqlInstance is not a function
    at Object.<anonymous> (C:\Users\Jiho.Choi.ROOT_MILLIMAN\Desktop\BoosterADS\excelvcs\routes\api\database.js:4:37)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Jiho.Choi.ROOT_MILLIMAN\Desktop\BoosterADS\excelvcs\server.js:38:21)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

0 个答案:

没有答案