Tag Archives: Nodejs study notes

events.js:160 throw er; // Unhandled ‘error’ event ^ Error: write after end at Serv

In the process of writing nodeJS project, When I deleted some data in the database, I made the judgment of various conditions first, and then deleted the data after meeting them. The first time it is deleted, it can be successfully deleted, then repeat the action of deleting the last time, the following error will occur:
Events. Js: 160
throw er; // Unhandled ‘error’ event
^

error: Write after end
the at ServerResponse. OutgoingMessage. Write (_http_outgoing. Js: 439:15)
the at F: \ \ userHandler SL js: 355:35
the at F: \ \ mon SL js: 84:5
the at handleCallback (F:\SL\node_modules\ lib\utils.js:120:56)
at F:\SL\ node_modules.js :1243:5
at F:\SL\node_modules\mongodb-core\lib\connection\pool.js:461:18
at Combinedtickcallback (internal/process/next_tick.js:67:7)
at process._tickcallback (internal/process/next_tick.js:98:9)

Some said that nodeJS version is too high, and some dropped from 7 to 6. My version is 6.

Solutions:
I add a return after each condition; Statement to solve the above problem.