Add data read file from csv dataset

This commit is contained in:
Sambo Chea 2021-03-26 08:42:51 +07:00
parent d2087fdc51
commit e9911d6b3b
2 changed files with 19 additions and 0 deletions

3
data/people.csv Normal file
View File

@ -0,0 +1,3 @@
id, name, age
1, Sambo Chea, 24
2, Ponlork Chea, 12
1 id name age
2 1 Sambo Chea 24
3 2 Ponlork Chea 12

16
src/index.js Normal file
View File

@ -0,0 +1,16 @@
const file = require('fs')
file.readFile('./data/people.csv', 'utf-8', (err, data) => {
if (err) {
console.error(err)
return
}
console.log(data)
const rows = data.split(/\r?\n/);
const header = rows[0].split(',').map(str => str.trim())
console.log(header)
});