1const http = require('http');
2const fs = require('fs');
3
4const url = 'www.example.com/image.png'; // link to file you want to download
5const path = 'app/assets/my_image_name.xlsx' // where to save a file
6
7const request = http.get(url, function(response) {
8 if (response.statusCode === 200) {
9 var file = fs.createWriteStream(path);
10 response.pipe(file);
11 }
12 request.setTimeout(60000, function() { // if after 60s file not downlaoded, we abort a request
13 request.abort();
14 });
15});
1const http = require('http');
2const fs = require('fs');
3
4const file = fs.createWriteStream("file.jpg");
5const request = http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", function(response) {
6 response.pipe(file);
7});
8