沿pipe道发送多个文件

我们使用快递4,现在我有这样的事情:

var express = require('express'), router = express.Router(); router.get('/local_modules/*', function (req, res, next) { var moduleName = req.url.match(/local_modules\/(.*?)\//).pop(1) res.sendFile(filePath + '.js'); } 

我想要做更多的事情

 router.get('/local_modules/*', function (req, res, next) { var moduleDir = req.url.match(/local_modules\/(.*?)\//).pop(1) fs.readdir(moduleDir, function(err, files) { files.forEach(function(f) { res.sendFile(path.join(moduleDir, f)); }) } } 

但是这不起作用。 我如何使用快递服务多个文件? 注意:不仅仅是一个目录中的所有文件(比如在这个例子中) – 这可能是通过app.use; express.static完成的app.use; express.static app.use; express.static ,但特定的文件集(例如我可能需要从bower.json获取文件列表)

除非您使用自己的特殊格式(标准多部分或其他格式),然后在客户端(例如,通过XHR)parsing,否则无法在单个响应中发送多个文件。

可能最简单的解决方法是将文件压缩(zip,7zip,tarball等),然后replace该文件。 然而,这个假设你想要用户下载它,而不是在浏览器中使用这些文件(除非你在浏览器中有一个zip等parsing器,并使用XHR)。