Error in Node: events.js: 160 throw er; // Unhandled 'error' event

0

I have the following error with Node v6.11.0 when doing any HTTP request other than GET .

The error is as follows:

  

events.js: 160 throw er; // Unhandled 'error' event   Error: Can not set headers after they are sent.       at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js: 357: 11)       at ServerResponse.header (/Users/sample/project/node_modules/express/lib/response.js:730:10)       at ServerResponse.send (/Users/sample/project/node_modules/express/lib/response.js:170:12)       at ServerResponse.json (/Users/sample/project/node_modules/express/lib/response.js:256:15)       at ServerResponse.send (/Users/sample/project/node_modules/express/lib/response.js:158:21)       at /Users/sample/project/controllers/product.js:15:27       at /Users/sample/project/node_modules/mongoose/lib/model.js:3748:16       at /Users/sample/project/node_modules/mongoose/lib/services/model/applyHooks.js:155:17       at _combinedTickCallback (internal / process / next_tick.js: 73: 7)       at process._tickCallback (internal / process / next_tick.js: 104: 9)   [nodemon] app crashed - waiting for file changes before starting ...

My operating system is a macOS Sierra v10.12.5 , and the MongoDB version (if it influences) that I use is the v3.4.4 .

I have been investigating the error and I have found that it is a fairly common error, for which there are many possible solutions, but of the following, among others that I have tried, have not been effective:

Option 1

rm -rf node_modules && npm cache clean && npm install

Option 2

brew uninstall node; 
brew prune;
rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;

brew install node;
which node
export NODE_PATH='/usr/local/lib/node_modules'

Option 3

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done

sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*

brew install node;
which node
export NODE_PATH='/usr/local/lib/node_modules'
    
asked by dddenis 09.06.2017 в 11:14
source

0 answers