Require CSV/TSV files directly in Browserify v2
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Version 0.0.6

Build Status Dependency Status devDependencies

Require CSV/TSV files directly in Browserify

When bundling an app using Browserify, it's often convenient to be able to include your .csv (comma-delimited) or .tsv (tab-delimited) files just as you would .json files (which Node natively understands). This small script allows you to require() them directly.


npm install node-csvify


Simply require your data files as you might anything else:

var states = require('./states.csv');
var countries = require('./countries.tsv');

Then, when running browserify, pass this module as a transformation on the command line.

browserify -t node-csvify script.js > bundle.js

Alternatively, you can specify this module as a transformation in your package.json file:

"browserify": {
    "transform": ["node-csvify"]

By doing so, you can include .csv or .tsv files without including the annoying -t node-csvify every time you run browserify.

How it works

This module uses D3's CSV and TSV parsing functions to convert the files to Javascript objects. (D3 itself is not a dependency, since it requires a C++ compiler downstream. Instead, I just ripped out the dsv parsing functions and repackaged them.) These functions are very smart about converting headers to property names. For example, this:


Becomes this:

[ { first: 'Chris', last: 'Wilson' },
  { first: 'Mike', last: 'Bostock' },
  { first: 'Miles', last: 'Davis' } ]

##Reducing file size

By default, this transformation converts the delimited files to JSON before passing them back to browserify. For large CSV files, this can greatly reduce the size, since the headers are now repeated for each record. (In the small example above, the CSV file is about 50 bytes, which the JSON verision is over 100 bytes.) While this sort of redundancy can be compressed very efficiently by gzip compression, you may still encounter instances where you want your data passed to its final destination as a compact string. You then assume responsibility for unpacking that string into a useful data format for your application.

There is no good way to pass arguments to transformations from the code itself. Instead, if you want this "no JSON" mode, you have to specify this in the package.json file:

"browserify": {
    "transform": ["node-csvify"],
    "transform-options": {
        "node-csvify": "nojson"

In "nojson" mode, the above example would pass a string to the application with the value:


##Version history

  • v0.0.6: Updated dependencies
  • v0.0.3: Extracted D3's dsv parsing and removed library as a dependency