Reputation: 1
While hitting the API I am getting the issue below.
Please let me the reason for getting this error:
api runnging on port 5000:
events.js:183
throw er; // Unhandled 'error' event
^
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:491:11)
at ServerResponse.setHeader (_http_outgoing.js:498:3
)
at ServerResponse.header (/Users/krishnamurthys/ecli
pse-workspace/vue_demo/node_modules/express/lib/response
.js:767:10)
at ServerResponse.send (/Users/krishnamurthys/eclips
e-workspace/vue_demo/node_modules/express/lib/response.j
s:170:12)
at ServerResponse.json (/Users/krishnamurthys/eclips
e-workspace/vue_demo/node_modules/express/lib/response.j
s:267:15)
at ServerResponse.send (/Users/krishnamurthys/eclips
e-workspace/vue_demo/node_modules/express/lib/response.j
s:158:21)
at appointment.save (/Users/krishnamurthys/eclipse-w
orkspace/vue_demo/api/server.js:30:16)
at /Users/krishnamurthys/eclipse-workspace/vue_demo/
node_modules/mongoose/lib/model.js:4528:16
at $__save.error (/Users/krishnamurthys/eclipse-work
space/vue_demo/node_modules/mongoose/lib/model.js:435:16
)
at /Users/krishnamurthys/eclipse-workspace/vue_demo/
node_modules/kareem/index.js:246:48
at next (/Users/krishnamurthys/eclipse-workspace/vue
_demo/node_modules/kareem/index.js:167:27)
at next (/Users/krishnamurthys/eclipse-workspace/vue
_demo/node_modules/kareem/index.js:169:9)
at Kareem.execPost (/Users/krishnamurthys/eclipse-wo
rkspace/vue_demo/node_modules/kareem/index.js:217:3)
at _handleWrapError (/Users/krishnamurthys/eclipse-w
orkspace/vue_demo/node_modules/kareem/index.js:245:21)
at /Users/krishnamurthys/eclipse-workspace/vue_demo/
node_modules/kareem/index.js:272:14
at _next (/Users/krishnamurthys/eclipse-workspace/vu
e_demo/node_modules/kareem/index.js:94:14)
[nodemon] app crashed - waiting for file changes before
starting...
[nodemon] restarting due to changes...
[nodemon] starting `node api/server.js`
api runnging on port 5000:
Upvotes: 1
Views: 79
Reputation: 459
This error is caused when you have code like this:
//say true
if(true){
//...
res.send();
}
res.send();
Upvotes: 1