stream-to-file.js 360 B

1234567891011121314
  1. var fs = require('fs'),
  2. needle = require('./..'),
  3. path = require('path');
  4. var url = process.argv[2] || 'http://www.google.com/images/errors/robot.png';
  5. var file = path.basename(url);
  6. console.log('Downloading ' + file + '...');
  7. needle
  8. .get(url)
  9. .pipe(fs.createWriteStream(file))
  10. .on('done', function() {
  11. console.log('Done!')
  12. })