NodeJS Promises 挂在 res.send(data)
NodeJS Promises hangs on res.send(data)
我正在 NodeJS 服务器上工作并执行一些文件解析并将结果发送回 AngularJS 客户端。我有下面的路由器调用:
router.post('/parseFile', upload.single('file'), function(req, res, next) {
let response = response_template
let promise = new Promise(function(resolve, reject) {
commands.parseFile(req.file.filename,
req.file.originalname,
resolve,
reject);
})
.then(function(result) {
console.log("This is working", result);
res.status(200);
res.send(data);
console.log("Should be here...?");
}, function(error) {
console.log("There was an error", error);
res.status(400);
res.send(data);
});
});
日志语句确实说 "This is working" 并且也打印出结果。但是,它不会在 res.send(data).
之后打印出 "Should be here...?" 语句。
数据也一直没有发送,客户端说没有收到回复。我查看了 Promise 文档,但无法理解我做错了什么。非常感谢任何帮助。谢谢!
data
未定义。您的那部分代码正在抛出并且正在吞噬异常。也许你的意思是使用 result
?
我正在 NodeJS 服务器上工作并执行一些文件解析并将结果发送回 AngularJS 客户端。我有下面的路由器调用:
router.post('/parseFile', upload.single('file'), function(req, res, next) {
let response = response_template
let promise = new Promise(function(resolve, reject) {
commands.parseFile(req.file.filename,
req.file.originalname,
resolve,
reject);
})
.then(function(result) {
console.log("This is working", result);
res.status(200);
res.send(data);
console.log("Should be here...?");
}, function(error) {
console.log("There was an error", error);
res.status(400);
res.send(data);
});
});
日志语句确实说 "This is working" 并且也打印出结果。但是,它不会在 res.send(data).
之后打印出 "Should be here...?" 语句。数据也一直没有发送,客户端说没有收到回复。我查看了 Promise 文档,但无法理解我做错了什么。非常感谢任何帮助。谢谢!
data
未定义。您的那部分代码正在抛出并且正在吞噬异常。也许你的意思是使用 result
?