Skip to content

Instantly share code, notes, and snippets.

@ivoba
Last active January 17, 2022 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivoba/29fc74ecd8ee6c2344c89d75418836e8 to your computer and use it in GitHub Desktop.
Save ivoba/29fc74ecd8ee6c2344c89d75418836e8 to your computer and use it in GitHub Desktop.
Filter a csv file with nodejs streams
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