title: NodeJS truncating POST request body to server
body: <p>I have the following code:</p>
  <pre><code>
  const http = require('http');
  const { Readable } = require('stream');
  
  const hostname = 'hostname';
  const port = 3000;
  const path = '/my/path';
  const method = 'POST';
  
  const body = JSON.stringify(VERYLARGEJSONOBJECT); // 343700+ bytes in size
  
  console.log(`Sending ${body.length} bytes:`);
  
  const options = {
  hostname,
  port,
  path,
  method,
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': body.length
    }
  };
  
  const req = http.request(options, (res) =&gt; {
    console.log(`Response statusCode: ${res.statusCode}`);
  });
  
  const stream = Readable.from([body]);
  
  stream.pipe(req);
  
  req.on('error', (error) =&gt; {
    console.error(error);
  });
  </code></pre>
  <p>When I send it from my desktop (x64, 16GB RAM) it sends even the largest of JSON objects just fine. But when I send it from an old i3 laptop (8GB RAM) the JSON object gets cut off, and cannot be parsed by the receiving server.</p>
  <p>I think this has to do with the stream that I'm using to buffer the output (since <code>req.write</code> gets saturated very quickly), but can't figure out exactly where I'm going wrong.</p>
  <p>I know that it is this sending code that is wrong, as I can send the same JSON object using postman, or using the exact same code on my desktop to the server and it works just fine.</p>
  <p>I have also tried cutting up the JSON data with:</p>
  <pre><code>  const body = JSON.stringify(VERYLARGEJSONOBJECT); // 343700+ bytes in size
    var re = new RegExp('.{1,' + 512 + '}', 'g');
    const packetChunks = body.match(re);
  
  ...
  
    const stream = Readable.from(packetChunks);
  
  </code></pre>
  <p>But it did not help</p>
  <p>Edit:</p>
  <p>Upon further investigation, it seems only the last 3 characters are missing, only when called on the i3 machine, which is very strange.
  The client is sending <code>&quot;inetLatency&quot;:17.996}</code> as the last part of the JSON packet, but the server is receiving <code>&quot;inetLatency&quot;:17.9</code>. I have tried adding a <code>req.write('   ');</code> (which is returning <code>true</code>) at the end and also not calling <code>req.end()</code> to see if that'd make the server receive the trailing data, but it still doesn't receive anything.</p>
  <p>Changing the stringify line to <code>const body = JSON.stringify(sendData) + '    ';</code> does ensure that the last 3 characters of the JSON object are received, but I don't like this hack because it doesn't fix the underlining problem.</p>