1// npm install --save csvtojson@latest
2const csv = require("csvtojson");
3const request = require('request');
4// Convert a csv file with csvtojson
5csv().fromStream(request.get('https://fileas.csv))
6  	.then(function(jsonArrayObj){
7  		//when parse finished, result will be emitted here.
8    	console.log(jsonArrayObj); 
9 	})1// Install
2npm i csvtojson
3
4// From CSV File to JSON Array
5/** csv file
6a,b,c
71,2,3
84,5,6
9*/
10const csvFilePath='<path to csv file>'
11const csv=require('csvtojson')
12csv()
13.fromFile(csvFilePath)
14.then((jsonObj)=>{
15    console.log(jsonObj);
16    /**
17     * [
18     * 	{a:"1", b:"2", c:"3"},
19     * 	{a:"4", b:"5". c:"6"}
20     * ]
21     */ 
22})1const { Parser } = require('json2csv');
2
3const myCars = [
4  {
5    "car": "Audi",
6    "price": 40000,
7    "color": "blue"
8  }, {
9    "car": "BMW",
10    "price": 35000,
11    "color": "black"
12  }, {
13    "car": "Porsche",
14    "price": 60000,
15    "color": "green"
16  }
17];
18
19const json2csvParser = new Parser();
20const csv = json2csvParser.parse(myCars);
21
22console.log(csv);