I am trying to convert arrays of objects to csv and write to a file or append if the file already exists. I found a package called "object-to-csv" but it requires Node 8 or higher while I'm on 7.8. It's not an option to upgrade, what alternative method is there for this?
1 Answer 1
You could replicate the functionality they've added in their implementation, it's a single file (index.js) of around 141 lines of code, not hard work to lift the implementation and make it work with node 7.
https://github.com/anton-bot/objects-to-csv/blob/master/index.js
Alternatively, you're looking to flatten an object (removing properties) keeping the values as an array, then export the array as a CSV file (using FS, or fs-extra).
Feel free to reach out if I can help further.
3 Comments
.map() syntax, replace it with something from Underscore.js (underscorejs.org) or Lodash (lodash.com), although it's a bit more effort on your part, the end-result with be compatible with your requirements. To be extra polite, you could even submit your version as a PR and see if they'd consider supporting older versions (they may not, but who knows).