title: How to export a large JSON data to an excel file
body: <p>I'm trying to export an array of 250000 objects to an excel file using <code>node.js</code> but the server fails everytime with:</p>
  
  <blockquote>
    <p>FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory</p>
  </blockquote>
  
  <p>I'm always starting the server with <code>npm --max-old-space-size=8000 start</code></p>
  
  <p>This is the part of my code where I'm trying to generate the excel file using the <code>excel4node</code> module:</p>
  
  <pre><code>// Create a new instance of a Workbook class
  var wb = new xl.Workbook();
  
  // Add Worksheets to the workbook
  var ws = wb.addWorksheet('Sheet 1');
  
  
  for(const [idx, request] of report.entries()) {
    let counter = 1;
    for(const [_, val] of Object.keys(request)) {
      ws.cell(idx + 1, counter).string(val);
      counter++;
    }
  }
  
  wb.write('Excel.xlsx');
  </code></pre>
  
  <p>This is the content of the <code>report</code> array:</p>
  
  <pre><code>[
      {
          "Page URL": "http://www.example.com",
          "Request URL": "http://use.typekit.net/yse3oeo.js",
          "Domain": "typekit.net",
          "OP Tag Category": "Data Management",
          "OP Tag Name": "Adobe TypeKit",
          "Registrar Name": "Adobe Systems Incorporated",
          "Method": "GET",
          "Type": "Script",
          "mimeType": "text/javascript",
          "Status": 200,
          "Content Encoding": "gzip",
          "Encoded Data Length": 8028,
          "Action": null,
          "IP Address": "92.123.20.219",
          "Geolocation": "FR",
          "Match Regex": null,
          "Not Match Regex": null,
          "Error": null,
          "Chrome Initiator": "http://example.com",
          "Final Page URL": null,
          "Initial Page Status": null
      }
      ...250000 more objects
  ]
  </code></pre>
  
  <p>I also tried to use the <code>mongo-xlsx</code> module, but it fails with the same error...</p>
  
  <p>Is there any way to improve my code efficiency in order to decrease the memory usage? Or maybe there better ways of doing this?</p>