Hsoule Hsoule - 1 year ago 112
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) {
.then(function(result) {
console.log("This is working", result);
console.log("Should be here...?");
}, function(error) {
console.log("There was an error", error);


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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download