title: How to response XMLHttpRequest in node.js
body: <p>By XMLHttpRequest, i send some data with </p>
  
  <pre><code> const xhr = new XMLHttpRequest()
  
    xhr.onreadystatechange = function (event) {
      if (xhr.readyState === 4 /** responseText is not available yet */) {
        const statusCode = xhr.status
        const responseText = xhr.responseText
        // some callback functions
      }
    }
    xhr.open('POST', url, true /** async */)
    xhr.setRequestHeader('Content-Type', 'text/plain')
    xhr.withCredentials = true 
    xhr.timeout = timeoutMillis 
    xhr.ontimeout = function (event) {
      // some time out error log
    }
    xhr.send(JSON.stringify(payloads))
  </code></pre>
  
  <p>and server side node.js server code is</p>
  
  <pre><code>   var httpPort = 3001
  var http = require('http')
     ,qs = require('querystring');
  http.createServer(function (req, res) {
          console.log(req.url + " "  + req.method);
     if( req.url == '/mytoken' &amp;&amp; req.method == 'POST'){
          console.log('start');
          var body = [];
          res.writeHead(200, {'Content-Type':'text/plain'});
          req.on('data', function(chunk){
                  body.push(chunk);
                  console.log('GOT DATA: ' + body);
          });
          res.end('OK');
     }else{
          res.writeHead(404, {'Content-Type': 'text/plain'});
          res.end('404 ERROR');
     }
  }).listen(httpPort);
  </code></pre>
  
  <p>I wrote server code like this. but, server did not send any response.</p>
  
  <p>It should be statusCode 200 with responseText 'OK'.</p>
  
  <p>I missed some? or did wrong way?</p>
  
  <p>EDIT 1: server code editted and it read data that sent to me</p>