node.jsstdinfscsv-write-stream

Node.js - write CSV file creates empty file in production, while OK in Mocha testing


This gist shows a code snippet that dumps an object into a CSV file. File writing is done using module csv-write-stream and it returns a promise.

This code works flawlessly in all the Mocha tests that I have made.

When the code is invoked by the main nodejs app (a server-side REPL application involving raw process.stdin and console.log invocations as interaction with the user), the CSV file is created, but it's always empty and no error/warning seems to be thrown.

I have debugged extensively the REPL code with node-debug and the Chrome dev tools: I am sure that the event handlers of the WriteStream are working properly: no 'error', all 'data' seems to be handled, 'close' runs, the promise resolves as expected.

Nevertheless, in the latter case the file is always 0 bytes. I have checked several Q&A's and cannot find anything as specific as this.

My questions are:

I am working on Windows 7. Node 6.9.4, npm 3.5.3, csv-write-stream 2.0.0.


Solution

  • I managed to fix this issue in two ways, either by: