Skip to content

saving csv to parent directories not working Windows 10 #14

Description

@nwheatle

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
})
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions