source: trip-planner-front/node_modules/needle/examples/download-to-file.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 583 bytes
Line 
1var fs = require('fs'),
2 needle = require('./..'),
3 path = require('path');
4
5var url = process.argv[2] || 'https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png';
6var file = path.basename(url);
7
8console.log('Downloading ' + file);
9
10needle.get(url, { output: file, follow: 3 }, function(err, resp, data){
11 console.log('File saved: ' + process.cwd() + '/' + file);
12
13 var size = fs.statSync(file).size;
14 if (size == resp.bytes)
15 console.log(resp.bytes + ' bytes written to file.');
16 else
17 throw new Error('File size mismatch: ' + size + ' != ' + resp.bytes);
18});
Note: See TracBrowser for help on using the repository browser.