【发布时间】:2018-05-15 06:47:41
【问题描述】:
我只有在调用 get 方法时才会收到此错误(不是每次)。
这是我的节点函数,它返回一个响应。
exports.GetDepartmentList = function (req, res) {
fs.readFile('./api/tempFiles/department.json', 'utf8', function (err,response) {
res.status(200).send({
success: true,
data: JSON.parse(response)
});
return res.json();
dbConn.close();
}).catch(function (err) {
res.status(500).send({
success: false,
message: err.message
});
return res.json();
dbConn.close();
});
};
我已经检查了 StackOverflow 的所有问题,但没有一个对解决我的问题有帮助。
【问题讨论】:
-
为什么写
return res.json();?还有dbConn.close();在它之后,因为return 终止了函数dbConn.close();永远不会被调用。使用res的send或json方法,不要同时使用 -
我删除了它,但它不起作用。发生同样的错误。@Dhyey
-
请用更新的代码编辑问题