Created
June 15, 2023 10:21
-
-
Save paambaati/f950149f4105a0c881fd6c19bf456e33 to your computer and use it in GitHub Desktop.
Parse CSV as a stream in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createReadStream } from 'fs'; | |
import { NODE_STREAM_INPUT, parse } from 'papaparse'; | |
(async () => { | |
const csvStream = createReadStream('machine-readable-business-employment-data-mar-2023-quarter.csv'); | |
const parseStream = parse(NODE_STREAM_INPUT); | |
csvStream.pipe(parseStream); | |
const data: Array<Array<string>> = []; | |
parseStream.on('data', (chunk: Array<string>) => { | |
data.push(chunk); | |
}); | |
parseStream.on('finish', () => { | |
console.log(data); | |
console.log(data.length); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment