Created
March 29, 2014 00:50
-
-
Save rgruesbeck/9846199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
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
"log" prints to the console, its "curl" that returns undefined if that make any sense... I need to understand what happens when "return data;" happens.
Its not getting returned form "curl", but I don't know how to get it to.