Skip to content

Instantly share code, notes, and snippets.

@shiffman
Created December 10, 2014 03:11
Show Gist options
  • Select an option

  • Save shiffman/e7fb25220cbefc1acec1 to your computer and use it in GitHub Desktop.

Select an option

Save shiffman/e7fb25220cbefc1acec1 to your computer and use it in GitHub Desktop.
Download an image from flickr with Node
var fs = require('fs');
var request = require('request');
var url = 'https://farm8.staticflickr.com/7484/15685407577_d19030d469_m.jpg';
var saveFile = 'test.jpg';
request.head(url, getImage);
function getImage(err, res, body) {
var req = request(url);
var pipe = req.pipe(fs.createWriteStream(saveFile));
pipe.on('close', finished);
}
function finished() {
console.log('downloaded: ' + url + ' and saved as ' + saveFile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment