Thursday, November 26, 2020

Reading and Writing CSV Files with Node.js

const csvFilePath='<path to csv file>'
const csv=require('csvtojson')
// Promise usage
csv()
.fromFile(csvFilePath)
.then((jsonObj)=>{
    console.log(jsonObj);
    /**
     * [
     *  {a:"1", b:"2", c:"3"},
     *  {a:"4", b:"5". c:"6"}
     * ]
     */ 
})
 
// Async / await usage
const jsonArray=await csv().fromFile(csvFilePath);

No comments:

Post a Comment