One of the common tasks we face is the processing of textual data files.
In this recipe, we will parse a CSV-formatted file by using an NPM library that supports reading from an input stream. In our example, we want to parse a contact database collecting customer counts by state. Our goal is to see which states have the most customers.
We will be using the node-csv NPM module. We will begin by installing the module:
npm install csv --save
If we inspect our sample CSV file, we see the first three lines that follow:
"first_name","last_name","company_name","address","city","county","state","zip","phone1","phone2","email","web" "James","Butt","Benton, John B Jr","6649 N Blue Gum St","New Orleans","Orleans","LA",70116,"504-621-8927","504-845-1427","[email protected]","http://www.bentonjohnbjr.com" "Josephine","Darakjy","Chanay, Jeffrey A Esq","4 B Blue Ridge Blvd","Brighton","Livingston","MI",48116,"810-292-9388","810-374- 9840","[email protected]","http...