Error while sending data to mongo db using angular framework

Hi all im trying work on a project using the tutorial which on youtube, however im getting the errror which says header issue, but i can get the data the issue is while posting the data. any help? i dont know im just learning at the moment. new to all this.

appreciate all your help experts.

There is error adding user to database
throw error;

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:526:11)
at ServerResponse.header (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\express\lib\response.js:771:10)
at ServerResponse.send (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\express\lib\response.js:170:12)
at ServerResponse.json (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\express\lib\response.js:267:15)
at ServerResponse.send (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\express\lib\response.js:158:21)
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\app.js:68:11
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\mongoose\lib\model.js:4891:16
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\mongoose\lib\helpers\promiseOrCallback.js:16:11
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\mongoose\lib\model.js:4914:21
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\mongoose\lib\model.js:495:16
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:246:48
at next (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:167:27)
at next (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:169:9)
at Kareem.execPost (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:217:3)
at _handleWrapError (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:245:21)
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:272:14
Emitted ‘error’ event on Function instance at:
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\mongoose\lib\model.js:4893:13
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\mongoose\lib\helpers\promiseOrCallback.js:16:11
[… lines matching original stack trace …]
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:272:14
at _next (C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:94:14)
at C:\Users\tapesh.patel\Desktop\Website\Kare-app\BackEnd\node_modules\kareem\index.js:507:38
at processTicksAndRejections (internal/process/task_queues.js:79:11) {

Welcome, tapesh.

Without seeing your code, it will be quite difficult for us to help.

It is likely you just have your routes (and subsequent CRUD operations) out of order to your server connection.

It might help if you spend some time debugging your order of operations.

Hope this helps

1 Like

Hi please find the screenshots below of my codes. Yes i’m trying to find the issue what is the header and all stands for and what does it do. All the tutorials are showing only the testing of API’s using postman where as my api is working fine with postman, and the tutorial which i have used to get the knowledge has no such error or he has’nt explains. Please see the link for the tutorial which i have refferd. Thanks for the help in advance sir

Code doc link

Screenshots are very difficult to work with. Please only use them as a last resort.

I am unable to debug the issue, further than it sounds like an issue with your database permissions. Ensure you have whitelisted your server address.

I am confused by what you have in your app.js file on line ~22 of ...PATCH< DELETE"). This does not look correct, and I would change the whole line to:

res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, HEAD");

Hope this helps

Hi i tried to correct this as well but i did not work. is there anything else ? you can give the solution ? sir

You will need to provide your code in some way: GitHub,, CodeSandbox, Glitch…any of these will do.