When I do a GET on a certain URI using the node.js \'request\' module;
var options = {uri:\"aURI\", headers:headerData};
request.get(options, function (error
This is how I solved the problem:
In main.js of the 'request' module I added one line:
Request.prototype.request = function () {
var self = this
self.setMaxListeners(0); // Added line
This defines unlimited listeners http://nodejs.org/docs/v0.4.7/api/events.html#emitter.setMaxListeners
In my code I set the 'maxRedirects' value explicitly:
var options = {uri:headingUri, headers:headerData, maxRedirects:100};
Although adding something to nodejs module is possible, it seems to be not the best way (if you try to run your code on other computer, the program will crash with the same error, obviously).
I would rather set max listeners number in your own code:
var options = {uri:headingUri, headers:headerData, maxRedirects:100};
request.setMaxListeners(0);
request.get(options, function (error, response, body) {
}
this is Extension to @Félix Brunet answer
Reason - there is code hidden in your app
How to find -
Eg - In my case i created 30 instances of winston log Unknowingly and it started giving error
Note : if u supress this error , it will come again afetr 3..4 days
It also happened to me
I use this code and it worked
require('events').EventEmitter.defaultMaxListeners = infinity;
Try it out. It may help
Thanks
I strongly advice NOT to use the code:
process.setMaxListeners(0);
The warning is not there without reason. Most of the time, it is because there is an error hidden in your code. Removing the limit removes the warning, but not its cause, and prevents you from being warned of a source of resource leakage.
If you hit the limit for a legitimate reason, put a reasonable value in the function (the default is 10).
Also, to change the default, it is not necessary to mess with the EventEmitter prototype. you can set the value of defaultMaxListeners attribute like so:
require('events').EventEmitter.defaultMaxListeners = 15;
I use the code to increase the default limit globally:
require('events').EventEmitter.prototype._maxListeners = 100;