Node.js 在内部发出另一个http请求后发送http响应时出错:";Can';t在发送后设置标题";

Node.js 在内部发出另一个http请求后发送http响应时出错:";Can';t在发送后设置标题";,node.js,express,Node.js,Express,在我的服务器中发出另一个http请求后,在Node.js中的express.js中发送http响应时出现以下错误 Error: Can't set headers after they are sent. _http_outgoing.js:491 at validateHeader (_http_outgoing.js:491:11) at ServerResponse.setHeader (_http_outgoing.js:498:3) at ServerRespo

在我的服务器中发出另一个http请求后,在Node.js中的express.js中发送http响应时出现以下错误

Error: Can't set headers after they are sent.
_http_outgoing.js:491
    at validateHeader (_http_outgoing.js:491:11)
    at ServerResponse.setHeader (_http_outgoing.js:498:3)
    at ServerResponse.header (/home/gustavo/Programacao/node-js/Imobiliaria/node_modules/express/lib/response.js:767:10)
    at ServerResponse.json (/home/gustavo/Programacao/node-js/Imobiliaria/node_modules/express/lib/response.js:264:10)
    at Request._callback (/home/gustavo/Programacao/node-js/Imobiliaria/api/controllers/property.js:71:41)
    at Request.self.callback (/home/gustavo/Programacao/node-js/Imobiliaria/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/gustavo/Programacao/node-js/Imobiliaria/node_modules/request/request.js:1161:10)
    at emitOne (events.js:116:13)
我认为该请求正在向我的服务器的se响应发送一些响应,但我无法找出原因和方式


我想先感谢能帮助我的人

请求包仅用于发出请求和获得响应。因此您不能发送
res.send()
通常,当您发送res(响应)2次或更多次时会导致此错误

示例导致相同的问题

route.get('/app',(req,res)=>{
 res.send()
 res.send()
})

如果存在类似的内容,请签入您的代码。

谢谢您的帮助:D

我刚刚发现了问题所在。我在服务器当前请求中发出的http请求是异步执行的。因此,在调用它之后,在发送对服务器请求的响应之前,我正在调用
res.end()
。我在其他http请求结果中发送的响应

route.get('/app',(req,res)=>{
 res.send()
 res.send()
})