objects-to-csv
objects-to-csv copied to clipboard
saving csv to parent directories not working Windows 10
I'm on windows 10, node v 10.15.3
I'm using csv-parser to read through a csv and alter the data row-by-row in an fs.createReadStream() call. After the read, I try to use objects-to-csv to save the altered array of objects as new csv file. this works if I use a filename like './file.csv'. But, when I try to save in parent directories, the file is created but empty, and 'error caught' is thrown for every row of csv that is parsed.
What am I doing wrong? I have tried many path.parse/path.resolve/etc to troubleshoot but I still cannot figure it out.
const file = "C:/path/to/my/file.csv" const csv = require('csv-parser') const ObjectsToCsv = require('objects-to-csv') absfilepath = path.resolve(file)
var csvarray = []; fs.createReadStream(absfilepath) .pipe(csv()) .on('data', function(data){ try { csvarray.push(cleanData(data)) } catch(err) { console.log('error caught') } }) .on('end', function(data) { // new ObjectsToCsv(csvarray).toDisk('./file.csv'); this works new ObjectsToCsv(csvarray).toDisk('../dirname/subdirname/file.csv'); // throws error on 'data' file created but empty }) })