2

我使用 Expressjs 3 和 Nodejs 0.10 创建了一个简单的文件下载器

function download(req, res, filepath, filename){
    res.header('Content-Type', 'application/force-download');
    res.header('Content-Type', 'application/octet-stream');
    res.attachment(filename);
    res.download(filepath, filename);
}

一切正常,但是当我使用下载管理器(例如 Internet 下载管理器)测试应用程序时,当我中止或取消下载(下载之前或下载期间)时,它会引发警告:

Trace
    at Socket.EventEmitter.addListener (events.js:160:15)
    at Socket.Readable.on (_stream_readable.js:653:33)
    at Socket.EventEmitter.once (events.js:179:8)
    at TCP.onread (net.js:512:26)

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

中止文件下载后如何删除侦听器?

4

1 回答 1

0

问题解决在Expressjs定义后
添加setMaxListeners(0) :

var express = require('express');

//expressjs 2.x
//var app = module.exports = express.createServer();

//expressjs 3.x
var app = module.exports = express();

//ADD BELOW CODE
app.setMaxListeners(0);


感谢@robertklep

于 2013-03-17T09:56:39.997 回答