node.js - sending multiple files down the pipe -
we're using express 4 , right have 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 wanna more like:
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 doesn't work. how can serve multiple files express? note: not files in directory (like in example) - can done app.use; express.static
, specific set of files (e.g. may need list of files bower.json)
there no way send multiple files in single response, unless use own special formatting (standard multipart or otherwise) , parse on client side (e.g. via xhr).
probably easiest workaround archive (zip, 7zip, tarball, etc.) files , serve archive instead. assumes want user download , not use files in browser (unless have zip, etc. parser in browser , use xhr).
Comments
Post a Comment