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:
process.stdin
in the equation, what is a way to create a simple, light-weight interaction with the user without having to write a webapp?I am working on Windows 7. Node 6.9.4, npm 3.5.3, csv-write-stream 2.0.0.
I managed to fix this issue in two ways, either by:
FileWriteStream
rather than on the 'end' event of the CSVWriteStream
process.exit()
I was using at the end of my operations with process.stdin
(this implies that this tutorial page may be in need of some corrections)