Skip to content

Instantly share code, notes, and snippets.

@scizers
Last active August 29, 2015 14:13
Show Gist options
  • Save scizers/881a82b6cbb200c368b2 to your computer and use it in GitHub Desktop.
Save scizers/881a82b6cbb200c368b2 to your computer and use it in GitHub Desktop.
Check if Image exists on Url while crawling
var validUrl = require('valid-url');
if(validUrl.isUri(imageUrl)){
request
.get(imageUrl)
.on('response', function (response) {
console.log(response.statusCode)
imagesName = (imagesName.split('?')[0])
if (response.statusCode == 200) {
this.pipe(fs.createWriteStream('images/' + imagesName)).on('close', function () {
cb();
});
} else {
cb();
}
}).on('error' , function(){
console.log('error testing')
cb();
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment