Created
May 4, 2012 08:33
-
-
Save xsyn/2593326 to your computer and use it in GitHub Desktop.
Problem is the response in res.send is undefined.
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
app.get('/products', function(req, res) { | |
var Client = http.createClient(80, 'local.10layer.com'); | |
var request = Client.request("GET", '/workers/api/section/products', {'host' : 'local.10layer.com'}); | |
request.addListener("response", function(response) { | |
var body = ""; | |
response.addListener("data", function(data) { //Add listener for the actual data | |
body += data; //Append all data coming from api to the body variable | |
}); | |
response.addListener("end", function() { //When the response ends, do what you will with the data | |
var response = JSON.parse(body); //In this example, I am parsing a JSON response | |
console.log(response); | |
}); | |
}); | |
request.end(); | |
res.send(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment