(node:7636) UnhandledPromiseRejectionWarning: 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 (C:\Users\username\path\Express\node_modules\express\lib\response.js:767:10)
at ServerResponse.send (C:\Users\username\path\Express\node_modules\express\lib\response.js:170:12)
at ServerResponse.json (C:\Users\username\path\Express\node_modules\express\lib\response.js:267:15)
at ServerResponse.send (C:\Users\username\path\Express\node_modules\express\lib\response.js:158:21)
at body.rows.forEach (C:\Users\username\path\Express\app.js:41:15)
at Array.forEach ()
at db.list.then (C:\Users\username\path\Express\app.js:40:19)
at
(node:7636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
Here is the code for the query:
app.get("/api/customers", (req, res, next) =>{
res.header("Access-Control-Allow-Origin", "http://localhost");
res.header("Access-Control-Allow-Methods", "GET, POST");
res.writeHead(200, {'Content-Type': 'application/json'});
db.list({ include_docs: true }).then((body) => {
body.rows.forEach((doc) => {
res.send(doc.doc);
});
});
});
I want to show data on the html page using angularjs.
Any help I will really appreciate.