-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.js
39 lines (32 loc) · 1003 Bytes
/
converter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const csv = require('csvtojson')
const fs = require('fs')
const path = require('path')
const convertToJson = (cvsPathFile='customer-data.csv') => {
const convertData = (cvsFilePath, callback)=>{
let jsonData = []
csv()
.fromFile(cvsPathFile)
.on('json',(jsonObj)=>{
jsonData.push(jsonObj)
})
.on('done',(error)=>{
console.log('Conversion process finished.')
callback(null, jsonData)
})
.on('error', (error)=>{
callback(error)
})
}
convertData(cvsPathFile, (error, data)=>{
if (error) {
console.log('Error: ' + error)
}
else
{
fs.writeFileSync(path.join(__dirname, 'customer-data.json'),JSON.stringify(data))
console.log('New Json file saved.')
}
global.process.exit(0)
})
}
convertToJson(process.argv[2])