You can do it like this with request
library:
const request = require('request');
const fs = require('fs');
var downloaded = 0;
request.get(url)
.on('data', function(chunk){
downloaded += chunk.length;
console.log('downloaded', downloaded);
})
.pipe(fs.createWriteStream(fileName));
Also, you can check this link to learn how to do it without request
package.
Update #1 (Pure NodeJS solution)
var http = require('http');
var fs = require('fs');
var download = function(url, dest, cb) {
var file = fs.createWriteStream(dest);
var downloaded = 0;
var request = http.get(url, function(response) {
response.pipe(file);
response.on('data', function(chunk){
downloaded += chunk.length;
console.log(downloaded);
})
file.on('finish', function() {
file.close(cb);
});
});
}
request
example. Would you mind providing an example also of how to do it without the request package based on that link you provided? – Taiga