0

I'm trying to send a series of status messages from Express to AngularJS using GET, as the status messages appear. I'm able to store the messages and then send them all at once, but I would like to send the messages to Angular as the stdout is created.

When i use res.send or res.json I get the Error: Can't set headers after they are sent. error, since they are calling res.end, but when I use res.write it does not actually write the data to angular until res.end is called.

Is there any way to get data to Angular from Node without calling res.end/resetting the res headers?

user3711502
  • 412
  • 5
  • 15

1 Answers1

0

This type of error you will get when you pass statements after sending a response.

For Example:-

res.send("something response");
console.log("abcdefghijklmnopqrstuvwxyz");
console.log("abcdefghijklmnopqrstuvwxyz");
res.send("sopmething response");

Will result in the error you are seeing, because once the response has been sent, the following res.send will not be executed.

Note:- If you want do anything, you should do it before sending the response.

For more Detail Visit:-error cant set headers after they are sent to the client

  • I'm aware of why the error is occurring, but is there any way to send a response using a method that does not contain `res.end`, which `res.send` and `res.json` both do? – user3711502 Sep 08 '17 at 19:58