Skip to content

Instantly share code, notes, and snippets.

@burabure
Last active August 29, 2015 14:24
Show Gist options
  • Save burabure/cf3cdcdcf1c3addeffba to your computer and use it in GitHub Desktop.
Save burabure/cf3cdcdcf1c3addeffba to your computer and use it in GitHub Desktop.
function requestHTML(url) {
return new Promise(function(resolve, reject){
request(url, function (err, res, body) {
if (err) reject(err);
if (!body) reject(new Error('not an html'));
resolve(body);
});
});
});
requestHTML('http://google.com')
.then(function(html){
//hacer algo con el html?
console.log(html);
})
.catch(function(err){
//hacer algo con el err?
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment