node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

How to read only the first ten rows of data

Open hetao92 opened this issue 4 years ago • 2 comments

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

hetao92 avatar Dec 18 '20 10:12 hetao92

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

jfoclpf avatar Jan 09 '22 23:01 jfoclpf

@hetao92 please close the issue if this solves your problem

jfoclpf avatar Feb 10 '22 12:02 jfoclpf