how to read a csv file in nodejs
const csv = require('csv-parser');
const fs = require('fs');
fs.createReadStream('data.csv')
.pipe(csv())
.on('data', (row) => {
console.log(row);
})
.on('end', () => {
console.log('CSV file successfully processed');
});
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const csvWriter = createCsvWriter({
path: 'out.csv',
header: [
{id: 'name', title: 'Name'},
{id: 'surname', title: 'Surname'},
{id: 'age', title: 'Age'},
{id: 'gender', title: 'Gender'},
]
});
const data = [
{
name: 'John',
surname: 'Snow',
age: 26,
gender: 'M'
}, {
name: 'Clair',
surname: 'White',
age: 33,
gender: 'F',
}, {
name: 'Fancy',
surname: 'Brown',
age: 78,
gender: 'F'
}
];
csvWriter
.writeRecords(data)
.then(()=> console.log('The CSV file was written successfully'));
$ npm i -s csv-parse
$ npm i -s csv-parser
Also in JavaScript:
- send file discord.js
- last element id javascript
- change id in jquery
- how to push string into array in javascript
- popper.min.js:4 Uncaught SyntaxError: Unexpected token 'export'
- discord javascript how to create a role
- pegar qual domínio eu estou javascript
- shuffle array javascript
- javascript square root
- javascript copy an array
- how to remove a value from an array and return the new array in javascript
- Material-ui add circle icon
- Access to fetch at 'https://api.myip.com/' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-
- jquery set checkbox checked unchecked
- node js post multipart/form-data
- jquery count selected options
- class query css js all
- angular scroll to element horizontally
- range javascript
- javascript date to string
- bootstrap show modal on page load
- how to copy text in the clipboard in js
- jquery on ready
- intval js