-1
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
backend server is running !
database connect
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are se
nt to the client
    at new NodeError (node:internal/errors:371:5)
    at ServerResponse.setHeader (node:_http_outgoing:576:11)       
    at ServerResponse.header (C:\Users\DevTool\Desktop\Project-Reac
t-Final\react\2\ecommerce-site\api\node_modules\express\lib\respons
e.js:776:10)
    at ServerResponse.send (C:\Users\DevTool\Desktop\Project-React-
Final\react\2\ecommerce-site\api\node_modules\express\lib\response.
js:170:12)
    at ServerResponse.json (C:\Users\DevTool\Desktop\Project-React-
Final\react\2\ecommerce-site\api\node_modules\express\lib\response.
js:267:15)
    at C:\Users\DevTool\Desktop\Project-React-Final\react\2\ecommer
ce-site\api\routes\auth.js:38:21
rnal/process/task_queues:96:5) {
  code: 'ERR_HTTP_HEADERS_SENT'
}
[nodemon] app crashed - waiting for file changes before starting...
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Your app is crashing due to ERR_HTTP_HEADERS_SENT, which means you're doing something with the response object AFTER sending a response. This is often due to some async code that is not being awaited on. For us to help, you'll need to provide code for the request handler that is causing this issue. – Chris Edgington Feb 22 '22 at 17:26

1 Answers1

0

Possibly problem is that you are sending the response in two different places or you are changing something in the res OBJ after sending the res the first time. To solve this make sure to use the keyword return before sending the response, this way you prevent the code from completing execution.

One small note: Always providing the code might speed up the process.

MoNajar
  • 94
  • 1
  • 2