0

我希望使用导出本地函数,module.exports = { router, functionName }但目前我正在努力这样做。我的代码如下所示 - 我想知道如何导出控制器“checkUserLoginCredentials”。

router.get('/', async function checkUserLoginCredentials(req, res) {
    //Controller code handling user login
});

我希望导出控制器以在单元测试中使用,但由于控制器是一个本地函数,我不能简单地将它放入module.exports,然后使用const { checkUserLoginCredentials } = require('path'). 任何帮助将不胜感激,谢谢。

4

1 回答 1

0

我建议将控制器移动到它自己的文件中,然后require("./path/to/controller")在路由和单元测试中使用它。

于 2021-01-24T23:52:41.523 回答