title: Write http request on a file with nodejs
body: <p>how can I save http request on a file?
  Im using nodejs as a server. I send data via ajax as it shows below</p>
  
  <pre><code>user_info = 
      {
          system_info: [
              {'browesr': browser},
              {'brower-version': version},
              {'cookies': cookieEnabled},
              {'os': os},
              {'os-version': osVersion}
          ]
      }
  }
  
  $.ajax({
      url: 'http://127.0.0.1:4560',
      data: {"info" : JSON.stringify(user_info)},
      type: 'POST',
      jsonCallback: 'callback',
      success: function(data) {
          var ret = jQuery.parseJSON(data);
          $('#lblResponse').html(ret.msg);
          console.log('success');
      },
      error: function(xhr, status, error) {
          console.log('Error:' + error.message);
          $('#lblResponse').html('Error connecting to the server.');
      }
  });
  </code></pre>
  
  <p>the post method works correctly and in server side the data is receive too.
  my problem is how to save data!
  I search and I find something about streaming. this is my nodejs server code.</p>
  
  <pre><code>var http = require('http');
  var fs = require('fs');
  
  http.createServer(function (req, res) {
  
      console.log('Request Received');
  
      res.writeHead(200, {
          'Context-Type': 'text/plain',
          'Access-Control-Allow-Origin': '*'
      });
  
      req.on('data', function (chunk) {
          var rstream = fs.createReadStream(JSON.parse(chund));
          var wstream = fs.createWriteStream('info.txt');
          rstream.pipe(wstream);
          str += chunk;
          console.log('GOT DATA');
      });
  
      res.end('{"msg": "OK"}');
  }).listen(4560, '127.0.0.1');
  console.log('Server running at http://127.0.0.1:4560/');
  </code></pre>
  
  <p>I use fs module and streaming, but didnt work at all, "info.txt" is near server code in the same directory.</p>
  
  <p>can anybody help me?</p>