Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read only the first ten rows of data #413

Open
hetao92 opened this issue Dec 18, 2020 · 2 comments
Open

How to read only the first ten rows of data #413

hetao92 opened this issue Dec 18, 2020 · 2 comments

Comments

@hetao92
Copy link

hetao92 commented Dec 18, 2020

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

@jfoclpf
Copy link

jfoclpf commented Jan 9, 2022

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
Copy link

jfoclpf commented Feb 10, 2022

@hetao92 please close the issue if this solves your problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants