Q:

http.get and node.js and JSON

I trying to develop a web app built on node.js that interacts with a PHP api. The following I trying to request a JSON object, that my PHP api creates. All I want to do is GET it then use in one of my .ejs templates.
Here is my node code, 
/*
 * GET home page.
 */

 //var request = require('reqeust');
 var http = require('http');
 var body = "";

exports.index = function(req, res){

    var options = {
        host: 'api.dev.com',
        port: 80,
        path: '/api/v1/posts',
        method: 'GET'
    };

    http.get(options, function(res) {
      console.log("Got response: " + res.statusCode);
      console.log(res);
      res.on("data", function(chunk) {
        console.log("BODY: " + chunk);
      });
    }).on('error', function(e) {
      console.log("Got error: " + e.message);
    });

    res.render('index', { data: body });
};

EJS
<%= data.title %>

however data.title is returning as undefined, my JSON object looks like below, and is valid.
[{"title":"This is the title of post 1","extract":"This is just a proof of concept more than anything at the moment","body":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n \t\t\t\tCras sed tellus massa, at commodo lectus. Ut metus nulla, sollicitudin id mollis ac, \n \t\t\t\tmalesuada eget libero. Duis sit amet auctor metus. Suspendisse et ornare dolor.\n \t\t\t\tMorbi non sodales sem. Nunc semper hendrerit dignissim. Proin id mollis purus.\n \t\t\t\tProin leo leo, feugiat ac sodales in, laoreet quis nisl. Etiam sed enim in libero\n \t\t\t\tpellentesque porttitor id eget diam.<\/p>","date_created":"01\/01\/2013 13:08:45","author":"Simon"}]

A:

try use request module, so you don't have to deal with chunks.
/*
 * GET home page.
 */

 var request = require('reqeust');
 var http = require('http');
 var body = "";

exports.index = function(req, res){

    var options = {
        host: 'api.dev.com',
        port: 80,
        path: '/api/v1/posts',
        method: 'GET'
    };

    request(options, function(err, res, data) { //chunks are already aggregated
      console.log("Got response: " + res.statusCode);
      data = JSON.parse(data); // you need to parse the JSON-string into real object
      console.log(data); // inspect what you got
      res.render('index', { data: data });
    })  
};

sure you need to npm install request, you already installed that?

