Skip to content

Instantly share code, notes, and snippets.

@rgruesbeck
Created March 29, 2014 00:50
Show Gist options
  • Save rgruesbeck/9846199 to your computer and use it in GitHub Desktop.
Save rgruesbeck/9846199 to your computer and use it in GitHub Desktop.
var http = require('http');
var bl = require('bl');
//get data from url.
function curl(url) {
http.get(url, function (res) {
res.pipe(bl(function (err, data) {
if (err) throw err;
else {
return data;
}
}));
});
};
//convert to string and print
function log(thing) {
console.log(thing.toString());
};
//map this array of urls to the output of the curl function / then print each.
[process.argv[2], process.argv[3], process.argv[4]].map(curl).forEach(log);
@shayanjm
Copy link

You don't want to 'return' from an async function.
How to use return values:

var something = somethingElse(thing);

The value of 'something' is populated by the return value of somethingElse() with param thing. If somethingElse() takes forever to return, then your entire application will have to wait until 'something' has a value.

Instead of return data;, you should actually deal with your data there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment