Last active
March 8, 2017 04:20
-
-
Save Muzietto/0c45d18335f8e0ea10020839592fb919 to your computer and use it in GitHub Desktop.
Promise to write data into a CSV file using npm module 'csv-write-stream'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
putPortfolioData = function(result, dataSinkName) { | |
return new Promise(function (resolve, reject) { | |
var filename = __dirname + dataSinkName, | |
writer = csvStream(), | |
ws = fs.createWriteStream(filename) | |
; | |
writer.on('error', function(error) { | |
reject(error); | |
}); | |
writer.on('end', function() { | |
resolve(result); | |
}) | |
writer.pipe(ws); | |
result.forEach(function(obj) { | |
writer.write(obj); | |
}); | |
writer.end(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code works flawlessly when running tests with Mocha. When it is invoked by the real nodejs app, the CSV file is created, but it is empty and no warning/error whatsoever is thrown. Pls see this question on SO
I am working on Windows 7. Node 6.9.4, Npm 3.5.3, csv-write-stream 2.0.0.