Skip to content

Instantly share code, notes, and snippets.



Created May 4, 2012
What would you like to do?
Problem is the response in res.send is undefined.
app.get('/products', function(req, res) {
var Client = http.createClient(80, '');
var request = Client.request("GET", '/workers/api/section/products', {'host' : ''});
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment