title: node http.get parse JSON body
body: <p>I'm trying to parse a JSON body from http.get. I know for a fact that the JSOn object is valid because I'm can eval successfully : </p>
  
  <pre><code>var json = document.body.innerText; 
  obj = JSON.parse(json);
  </code></pre>
  
  <p>However, this code returns an error : </p>
  
  <pre><code>undefined:1
  undefined{
  Syntax error, Unexpected token u
  </code></pre>
  
  <p>My Node code :</p>
  
  <pre><code>function getCategories(callback){
      var body;
      var urlCats = "http://...";
      process.send(urlCats);
      http.get(urlCats, function(res){
          res.on('data', function (chunk) {
              body += chunk;
          });
          res.on('end', function () {
              callback(JSON.parse(body));
          });
      })
  }
  </code></pre>
  
  <p>I have already seen <a href="https://stackoverflow.com/questions/11826384/calling-a-json-api-with-node-js">Calling a JSON API with Node.js</a> but I don't think it applies as I already get the body properly (callback(body) prints OK although the object starts with : undefined{). Any suggestions? Should I just cut the 'undefined' part of my body string? there must be something I'm missing! Thanks!</p>