node.js-请求-如何"emitter.setMaxListeners()"? [英] node.js - request - How to "emitter.setMaxListeners()"?

查看:615
本文介绍了node.js-请求-如何"emitter.setMaxListeners()"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用node.js的请求"模块对某个URI进行GET时;

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) {
}

错误消息是:

[Error: Exceeded maxRedirects. Probably stuck in a redirect loop.]

,并且还会显示以下消息:

"(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit."

我如何setMaxListeners?

推荐答案

我强烈建议不要使用该代码:

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.

如果您出于正当理由达到了限制,请在函数中输入一个合理的值(默认值为10).

If you hit the limit for a legitimate reason, put a reasonable value in the function (the default is 10).

此外,要更改默认值,也不必弄乱EventEmitter原型.您可以像这样设置defaultMaxListeners属性的值:

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;

这篇关于node.js-请求-如何"emitter.setMaxListeners()"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆