【问题标题】:Dynamically writing stdout from Express to AngularJS将标准输出从 Express 动态写入 AngularJS
【发布时间】:2017-09-09 03:48:24
【问题描述】:

当状态消息出现时,我正在尝试使用GET 从 Express 向 AngularJS 发送一系列状态消息。我能够存储消息,然后一次发送它们,但我想在创建标准输出时将消息发送到 Angular。

当我使用res.sendres.json 时,我收到Error: Can't set headers after they are sent. 错误,因为他们正在调用res.end,但是当我使用res.write 时,它实际上并没有将数据写入角度,直到res.end 是叫。

有什么方法可以在不调用res.end/重置res headers的情况下从Node获取数据到Angular?

【问题讨论】:

  • 你能分享一些代码来帮助你吗\

标签: angularjs node.js express response


【解决方案1】:

在发送响应后传递语句时会出现这种类型的错误。

例如:-

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

将导致您看到的错误,因为一旦发送响应,将不会执行以下 res.send。

注意:- 如果你想做任何事情,你应该在发送响应之前做。

更多详情请访问:-error cant set headers after they are sent to the client

【讨论】:

  • 我知道为什么会发生错误,但是有什么方法可以使用不包含res.end 的方法发送响应,res.sendres.json 都可以这样做?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 1970-01-01
  • 2012-06-08
  • 1970-01-01
  • 2014-07-03
相关资源
最近更新 更多