node-csvtojson
node-csvtojson copied to clipboard
How to read only the first ten rows of data
I only need the first few lines of data in the file to be displayed on the web page, how to avoid reading the entire file
you can try to use the stream reader
const fs = require('fs')
const csv = require('csvtojson')
csv()
.fromStream(fs.createReadStream('/pathToFile', { end: 1024 }))
.subscribe((json) => {
console.log(json)
},
(err) => {
throw err
},
() => {
console.log('success')
})
Check the stremReaderOptions here
@hetao92 please close the issue if this solves your problem