Sending multiple files by pipe

we use express 4, and now I have something like this:

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');
}

and I want to do something more:

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

}

But that does not work. How can I serve multiple files using an expression? Note: not only all the files in the directory (for example, in the example) that can probably be executed with app.use; express.static, but a specific set of files (for example, I may need to get a list of files from bower.json)

+4
source share
1 answer

There is no way in one answer to send multiple files, unless you use your own special formatting (standard multi-part or otherwise), and then parse it on the client side (for example, via XHR).

, (zip, 7zip, tarball ..) , . , , , ( zip .. XHR).

+5

All Articles