和之间有什么不同module.exports = testMethod ;
,module.exports = { testMethod } ;
因为当我使用module.exports = testMethod ;
它时会抛出如下错误。
错误:Route.get() 需要一个回调函数,但得到一个 [object Undefined]
但我可以接受module.exports = { testMethod } ;
整个代码是
const testMethod = asyncErrorWrapper(async (req, res, next) => {
const information = req.body;
const question = await Question.create({
title: information.title,
content: information.content,
user: req.user.id,
});
res.status(200).json({
success: true,
data: question,
});
});
module.exports = { testMethod };