O'Reilly logo

CoffeeScript Application Development Cookbook by Mike Hatfield

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing CSV files

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.

Getting ready

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","jbutt@gmail.com","http://www.bentonjohnbjr.com" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required