Error [ERR_HTTP_HEADERS_SENT] Cannot set headers after they are sent to the client

at ServerResponse.setHeader (_http_outgoing.js:470:11) at ServerResponse.header (C:rootnode_modulesexpresslibresponse.js:771:10) at ServerResponse.send (C:rootnode_modulesexpresslibresponse.js:170:12) at ServerResponse.json (C:rootnode_modulesexpresslibresponse.js:267:15) at ServerResponse.send (C:rootnode_modulesexpresslibresponse.js:158:21) at grade.save (C:rootrouteapilistsData.js:223:32) at C:rootnode_modulesmongooselibmodel.js:4604:16 at C:rootnode_modulesmongooselibutils.js:268:11 at $__save.error (C:rootnode_modulesmongooselibmodel.js:472:16) at C:rootnode_moduleskareemindex.js:246:48 at next (C:rootnode_moduleskareemindex.js:167:27) at next (C:rootnode_moduleskareemindex.js:169:9) at Kareem.execPost (C:rootnode_moduleskareemindex.js:217:3) at _handleWrapError (C:rootnode_moduleskareemindex.js:245:21) at C:rootnode_moduleskareemindex.js:272:14 at _next (C:rootnode_moduleskareemindex.js:94:14) Emitted 'error' event at: Please help, I was facing with this … Read more

async function inside new async function

I need to fetch data from Mongo db using mongoose then send some request using node-fetch. So I created below async function async function mainThree() { await ProvinceList.find({}).then((data) => { data.forEach((provience) => { console.log(provience.id) let response = await fetch(`https://xxxx.com/api/getSubAddressList?addressId=${provience.id}`, { "headers": { "accept": "application/json, text/plain, */*", "accept-language": "en-US,en;q=0.9,si;q=0.8", "cache-control": "no-cache", }, "referrer": "https://www.xxxx.com/", "referrerPolicy": "strict-origin-when-cross-origin", … Read more