title: cors unexpected end of JSON input
body: <p>I am parsing my json on <code>end</code> but I am still receiving this error.</p>
  
  <pre><code>'use strict';
  const http = require('http');
  const tools = require('./tools.js');
  
  const server = http.createServer(function(request, response) {
      console.log("received " + request.method + " request from " + request.headers.referer)
  
      var body = "";
      request.on('error', function(err) {
          console.log(err);
      }).on('data', function(chunk) {
          body += chunk;
      }).on('end', function() {
          console.log("body " + body);
          var data = JSON.parse(body); // trying to parse the json
          handleData(data);
      });
  
      tools.setHeaders(response);
      response.write('message for me');
      response.end();
  });
  server.listen(8569, "192.168.0.14");
  
  console.log('Server running at 192.168.0.14 on port ' + 8569);
  </code></pre>
  
  <p>Data being sent from the client:</p>
  
  <pre><code>var data = JSON.stringify({
      operation: "shutdown",
      timeout: 120
  });
  </code></pre>
  
  <p>I successfully receive the json but I am unable to parse it.</p>
  
  <p>Update:</p>
  
  <p>I've updated the code to include the server code in its entirety.</p>
  
  <p>To be perfectly clear, using the following code:</p>
  
  <pre><code>....
  }).on('end', function() {
          console.log("body " + body);
          var json = JSON.parse(body); // trying to parse the json
          handleData(json);
  });
  </code></pre>
  
  <p>I get this:</p>
  
  <p><img src="https://i.imgur.com/8BVOt3x.png" alt="description"></p>
  
  <p>However, this:</p>
  
  <pre><code>....
  }).on('end', function() {
      console.log("body " + body);
      //var json = JSON.parse(body); // trying to parse the json
      //handleData(json);
  });
  </code></pre>
  
  <p>produces this</p>
  
  <p><img src="https://i.imgur.com/I0nFbu0.png" alt="description"></p>