I am creating an xlsx workbook using the module exceljs and then I would like to send it as an attachment through my express middleware.
I create and save my workbook in a stream using the following code as shown in documentation of the module
var stream = fs.createWriteStream('test.xlsx');
// write to a stream
workbook.xlsx.write(stream)
.then(function() {
// done
});
where stream is a writable stream.
My problem is that I can't understand how to handle the stream in order to send it.
Trying to pipe it to res stream.pipe(res)
gives my an error that is not readable stream to pipe it.
What is the best course of action for me now?
p.s. I could save it into a file in the server and then read the file and send it through express. That would not help me as the attachment is not needed afterwards, and is a workaround which I do not like.