Hsoule Hsoule - 5 months ago 25
Node.js Question

NodeJS Promises hangs on res.send(data)

I'm working on a NodeJS server and performing some file parsing and sending back the result to an AngularJS client. I have the router call below:

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);
});


});

The log statements do say "This is working" and prints out the result too. However, it does not print out the "Should be here...?" statement after the res.send(data).

The data is also never sent and the client says no response was received. I've looked through the Promise documentation but I can't understand what I'm doing wrong. Any help is really appreciated. Thanks!

daf daf
Answer

data is not defined. That part of your code is throwing and the exception is being swallowed. Perhaps you mean to use result?

Comments