title: Node.js - save xlsx to disk
body: <p>I am using Node.js and <a href="https://github.com/SheetJS/js-xlsx" rel="nofollow">js-xlsx</a> for generating new Excel files.
  When a new file is generated I want it to be saved to local disk.</p>
  
  <p>This code is used generating and downloading a new Excel file, how can it be stored to disk instead?</p>
  
  <pre><code>FileManagement.generateExcelFile("xlsx-filtered-list", "error-sheet", finalResult, res);
  
  generateExcelFile(fileName, sheetName, data, res) {
      const workSheet = sheet_from_array_of_arrays(data);
      const workBook = new Workbook();
  
      workBook.SheetNames.push(sheetName);
      workBook.Sheets[sheetName] = workSheet;
  
      const workBookOptions = { bookType:'xlsx', bookSST:false, type:'binary' };
      const workBookFile = xlsx.write(workBook, workBookOptions);
  
      res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
      res.setHeader('Content-Disposition', 'attachment; filename='+fileName);
      res.end(workBookFile, 'binary');
  
      // Functions work Excel generation (don't touch)
      function Workbook() {
          if(!(this instanceof Workbook)) return new Workbook();
          this.SheetNames = [];
          this.Sheets = {};
      }
  
      function sheet_from_array_of_arrays(data) {
          const workSheet = {};
          const range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }};
          for(let R = 0; R != data.length; ++R) {
              for(let C = 0; C != data[R].length; ++C) {
                  if(range.s.r &gt; R) range.s.r = R;
                  if(range.s.c &gt; C) range.s.c = C;
                  if(range.e.r &lt; R) range.e.r = R;
                  if(range.e.c &lt; C) range.e.c = C;
                  const cell = {v: data[R][C] };
                  if(cell.v == null) continue;
                  const cell_ref = xlsx.utils.encode_cell({c:C,r:R});
  
                  if(typeof cell.v === 'number') cell.t = 'n';
                  else if(typeof cell.v === 'boolean') cell.t = 'b';
                  else if(cell.v instanceof Date) {
                      cell.t = 'n'; cell.z = xlsx.SSF._table[14];
                      cell.v = datenum(cell.v);
                  }
                  else cell.t = 's';
  
                  workSheet[cell_ref] = cell;
              }
          }
          if(range.s.c &lt; 10000000) workSheet['!ref'] = xlsx.utils.encode_range(range);
  
          return workSheet;
      }
  }
  </code></pre>