_http_outgoing.js:504
throw new Error('Can\'t set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:504:11)
at ServerResponse.setHeader (_http_outgoing.js:511:3)
at Array.write (D:\GitSpace\fbms\node_modules\_finalhandler@1.0.3@finalhandl
er\index.js:254:9)
at listener (D:\GitSpace\fbms\node_modules\_on-finished@2.3.0@on-finished\in
dex.js:169:15)
at onFinish (D:\GitSpace\fbms\node_modules\_on-finished@2.3.0@on-finished\in
dex.js:100:5)
at callback (D:\GitSpace\fbms\node_modules\_ee-first@1.1.1@ee-first\index.js
:55:10)
at IncomingMessage.onevent (D:\GitSpace\fbms\node_modules\_ee-first@1.1.1@ee
-first\index.js:93:5)
at emitNone (events.js:105:13)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
Program node app.js exited with code 1
If the debugging mode is not enabled, there will be no error. Page loading, req, and res are all normal.
There is a problem with the code, and it has nothing to do with debugging mode. The response has been sent, but you still want to modify the response header that has been sent.
Once the response.end() method is called, it means that the response has been completed and sent. After that, methods such as response.writeHead() and other methods that modify the response must not be called.