NodeJS 将 JSON 转换成 EXCEL(CSV)
最近要使用LeanCloud的数据,导出来是一个JSON格式的文件,妹子根本没办法打开处理,于是使用 Node 将这个JSON文件转换成CSV格式的文件,让她能在EXCEL中打开使用。 方法 用到了2个库,一个是 zemirco/json2csv,另外一个就是系统自带的 fs 模块了。json2csv 这个库非常强大,可以在命令行及Javascript module方式使用,具体使用参考github地址即可。 代码 var fs = require('fs'); const Json2csvParser = require('json2csv').Parser; const fields = ['car', 'price', 'color']; const myCars = [ { "car": "Audi", "price": 40000, "color": "blue" }, { "car": "BMW", "price": 35000, "color": "black" }, { "car": "Porsche", "price": 60000, "color": "green" } ]; const json2csvParser = new Json2csvParser({ fields }); const csv = json2csvParser.parse(myCars); console.log(csv); fs.writeFile("./out.csv", csv, function(err) { if(err) { return console. 继续阅读Easy Way to Install Nodejs on Ubuntu 16.04(Useful!!!!)
There are many methods to install on Ubuntu, such as NVM, n, PPA, complie, But if just want to install specific version, it would be easily. Just do as follow.