Skip to content

Instantly share code, notes, and snippets.

@aaronblondeau
Created August 20, 2016 15:31
Show Gist options
  • Save aaronblondeau/94d45910fff586800067f86cef083966 to your computer and use it in GitHub Desktop.
Save aaronblondeau/94d45910fff586800067f86cef083966 to your computer and use it in GitHub Desktop.
Promise.coroutine (base code - callbacks only)
var request = require('request');
var fs = require('fs');
// Note that we cannot use a try catch around all this :-(
request.get('https://s3.amazonaws.com/aaronblondeau/widgets/widgets.json', (err, response, body) => {
if(err) {
console.error(err);
}
var data = JSON.parse(body);
fs.writeFile('./widgets.json', JSON.stringify(data.widgets), (err) => {
if(err) {
console.error(err);
}
console.log("Done.");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment