Reputation: 99
I need to make a downloadable link for a file, but, for certain reasons I cannot load file directly. Is there any way to stream a file from its destination to remote server and immediately (at the same time) from server to user. Thank you.
Upvotes: 1
Views: 840
Reputation: 106696
You can use fs.createReadStream()
and pipe that to the response object. For example:
var fs = require('fs'),
http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/javascript' });
fs.createReadStream(__filename).pipe(res);
}).listen(8000);
Upvotes: 1