So we have a CSV file with a member list and we want to filter all empty emails.
FirstName,LastName,Email Max,Mustermann,email@example.com Maxi,Hasnoemail,
With nodejs streams this is almost a one liner.
We will use the csv package from the CSV project which has some sophisticated packages to parse and transform csv data with nodejs streams.
npm install csv
We will further use node as ESM (ECMAScript modules) to be shiningly modern and so lets create a file:
Note the .mjs extension, which will tell node to interprete this as ESM. (Since nodejs v12.20.0 && v14.13.0)
We import the packages and create the filesystem streams to read the file, then built a pipeline with the streams and the single steps to process the data and write the results into a new file.
Ok let’s go: