Last active
January 17, 2022 08:41
-
-
Save ivoba/29fc74ecd8ee6c2344c89d75418836e8 to your computer and use it in GitHub Desktop.
Filter a csv file with nodejs streams
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 {pipeline} from 'stream'; | |
import {parse, transform, stringify} from 'csv'; | |
import {createReadStream, createWriteStream} from 'fs'; | |
pipeline( | |
createReadStream(`./members.csv`), | |
parse(), | |
transform(data => data[2] !== '' ? data : null), | |
stringify({}), | |
createWriteStream(`./members_filtered.csv`), | |
err => err ? console.error('Pipeline failed.', err) : console.log('Pipeline succeeded.') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment