title: How to set JSON data in node.js response object?
body: <p>I am using html on client side and my server side code is on node.js. I have some url's defined in to the nodejs application and I am calling them from my client html file. From node I am calling my REST application which is at another server. This rest application is written in Jersey java web services. I am able to call node.js from my html and from node code I am getting response from Jersey web service module. After receiving this response I am setting it to response object of node.js but this response is not available on html jquery ajax call.</p>
  
  <pre><code>$.ajax({
      type :"POST",
      dataType: 'json',
      data: jsontest,
      url: 'http://&lt;code&gt;localhost&lt;/code&gt;:9999/hello',
      success: function(data) {
          console.log('success');
          console.log(data);
          console.log(data.id);
      }, error : function(response) {
          console.log(JSON.stringify(response));
      }
  });
  </code></pre>
  
  <p>Server side code:</p>
  
  <pre><code>var tmp = req;
  var authentication = JSON.stringify(tmp.body.authenticationKey);
  
  console.log("authentication :- "+authentication);
  
  requestObj({
      url : "http://&lt;code&gt;restserver&lt;/code&gt;:port/restmodule/controller/hello",
      method : "POST",
      headers : { "Content-Type" : "application/json","pubKey":authentication},
      body : JSON.stringify(tmp.body)
    },
    function (error, res, body) {
      indexresponseBody = JSON.stringify(JSON.parse(body).message);
    }
  );
  
  res.writeHead(200, {'content-type':'text/html'});
  
  console.log("JSON returned from REST "+indexresponseBody);
  
  res.write(indexresponseBody);
  res.end();
  </code></pre>
  
  <p>I am able to get the json and this is printed on node server console. But when I am writing this json to the response(res) object on firebug console I am not able to see this json. Can anybody tell me how can I get this response.</p>