How to send parsed .csv file as a byte array or ArrayBuffer data from Node.js backend to AngularJS frontend?

I’m working on AngularJS app.
Module I’m currently working on should be able to either show a preview of a spreadsheet file or allow to download it.

The steps:

  1. When clicked on “Preview File” it should send request with needed file’s name as a parameter of POST request.
  2. Backend will find neede file, which is a .csv file, convert it to byte array type and send it to frontend.
  3. Frontend should handle this byte array and convert it to .xls or .xlsx filetype
  4. The spreadsheet data should be opened in some small preview read-only window, like 1000×1000 px.

The POST request line looks like that:
this.$ + 'endpoint/getFile', params, {responseType: "arraybuffer", showLoadingOverlay: true}).

The response looks indeed like ArrayBuffer: three of it in one object, i.e. Uint8Array, Uint16Array and Uint32Array.

The code which should read this and convert to content suitable for preview is not working:

const byteArray = new Uint8Array(data);
const blob = new Blob([byteArray], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const objectUrl = URL.createObjectURL(blob);
this.$, 'C-Sharpcorner', 'width=1000,height=1000');

Because when created the blob, it already has 0 length in bytes, so there’s no data inside.

The matter of visualising the .xls in browser window, I think, can be achieved with canvas-datagrid library. Haven’t used but it looks cool.

Also, I have a problem with trying to set up a mock data for node.js (and AngularMock), for local testing when there’s no data on a java backend.

I’m using ‘fs’ and ‘csv-parse’:

const fs = require('fs');
const csvParse = require("csv-parse/lib/es5");

module.exports = function stir(app) {
const getFile = () => {
  const csvOutput = csvParse('../static/someData.csv', (parsed) => {
    return parsed;
};'/stir/getFile', (req, res) => res.json(getFile()));

Which results in error: TypeError: path must be a string or Buffer.

What is the proper way of parsing the .csv using ‘csv-parse’ and sending parsed data as an ArrayBuffer to frontend in Node and AngularMock?
csv-parse docs are telling that underneath, the lib will convert the parsed object to node stream.
So why that error happens?

Source: AngularJS