Skip to content

Instantly share code, notes, and snippets.

@DTrejo
Forked from joelklabo/moving data around
Created January 24, 2011 05:24
Show Gist options
  • Save DTrejo/792876 to your computer and use it in GitHub Desktop.
Save DTrejo/792876 to your computer and use it in GitHub Desktop.
function findBeer(words) {
//...code...
getResults(word, function(err, result){
// now you can access things!
console.log(err, result);
});
}
function getResults(word, callback) {
// ...code...
request({uri:db}, function (err, resp, b) {
if (err) throw err;
if (resp.statusCode !== 200) throw new Error("Could not get document. " + b );
response = JSON.parse(b);
// important part!
callback(null, "this was a test");
// unless there's no chance of an error, it's generally best to
// pass the error as first arg, and results as the rest of the arguments.
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment