首页 > 解决方案 > 如何将 csv 文件转换为节点中的对象?

问题描述

我一直在尝试使用 nodejs 包'csvtojson',我可以返回数据的控制台日志,但我似乎无法弄清楚如何将它存储在变量/对象中。npmjs.comGitHub 页面上的文档非常简短,只展示了一种使用方式。

稍后我试图在我的 js 文件中对这些数据做更多的事情,所以我需要它在一个对象中。

到目前为止,我有:

const convertCsv = require('csvtojson').Converter;
const csv = new convertCsv;
const filePath = (relative path to file);

csv.fromFile(filePath).then((jsonObj)=>{
  //this is working
  console.log(jsonObj);
})
let kO = csv.fromFile(filePath);
//this is not
console.log(kO);

标签: javascriptnode.jsjsoncsvcsvtojson

解决方案


推荐阅读