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, response, body) { }
The error message is:
[Error: Exceeded maxRedirects. Probably stuck in a redirect loop.]
and there is also the following message:
"(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit."
How do I setMaxListeners
?
Many objects in a Node emit events, for example, a net. Server emits an event each time a peer connects to it, an fs. readStream emits an event when the file is opened. All objects which emit events are the instances of events.
The EventEmitter is a module that facilitates communication/interaction between objects in Node. EventEmitter is at the core of Node asynchronous event-driven architecture. Many of Node's built-in modules inherit from EventEmitter including prominent frameworks like Express. js.
After installing request module you can check your request version in command prompt using the command. 3. After that, you can create a folder and add a file for example index. js, To run this file you need to run the following command.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With