csv-parser vs csvtojson vs fast-csv vs papaparse
CSV Parsing Libraries for JavaScript Applications
csv-parsercsvtojsonfast-csvpapaparseSimilar Packages:

CSV Parsing Libraries for JavaScript Applications

csv-parser, csvtojson, fast-csv, and papaparse are JavaScript libraries for parsing CSV (Comma-Separated Values) data into structured formats like arrays or objects. They differ significantly in architecture, environment support, and feature sets. csv-parser and csvtojson are Node.js-only and focus solely on parsing. fast-csv works in both Node.js and browsers and supports both parsing and generating CSV. papaparse is browser-first but also runs in Node.js, offering robust error handling, streaming, and web worker support for large files.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
csv-parser01,49529.5 kB63a year agoMIT
csvtojson02,038356 kB1206 months agoMIT
fast-csv01,7767.03 kB608 months agoMIT
papaparse013,425264 kB212a year agoMIT

Parsing CSV in the Browser and Node.js: csv-parser vs csvtojson vs fast-csv vs Papa Parse

When you need to read or process CSV data in JavaScript β€” whether in a browser app or a Node.js backend β€” choosing the right parser can make a big difference in performance, memory use, and developer experience. The four main contenders (csv-parser, csvtojson, fast-csv, and papaparse) each take a different approach. Let’s compare them on real engineering concerns.

πŸ§ͺ Core Architecture: Streams vs Callbacks vs Promises

csv-parser is built around Node.js streams. It reads input line by line and emits 'data' events for each parsed row. This makes it memory-efficient for large files but only works in Node.js.

// csv-parser (Node.js only)
const fs = require('fs');
const csv = require('csv-parser');

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('data', (row) => console.log(row))
  .on('end', () => console.log('Finished'));

csvtojson uses a callback-based API with optional promise support via .then(). It loads the entire file into memory before parsing, so it’s not ideal for very large datasets.

// csvtojson (Node.js only)
const csv = require('csvtojson');

csv()
  .fromFile('data.csv')
  .then((jsonObj) => console.log(jsonObj));

// Or with callbacks
csv().fromFile('data.csv', (err, jsonObj) => {
  if (err) throw err;
  console.log(jsonObj);
});

fast-csv supports both streaming and promise-based parsing, and works in both Node.js and browsers (via bundlers like Webpack). Its streaming mode is memory-efficient; its promise mode is convenient for small files.

// fast-csv (Node.js stream)
const fs = require('fs');
const csv = require('fast-csv');

fs.createReadStream('data.csv')
  .pipe(csv.parse({ headers: true }))
  .on('data', (row) => console.log(row))
  .on('end', (rowCount) => console.log(`Parsed ${rowCount} rows`));

// fast-csv (promise, works in browser too)
csv.parseString('name,age\nAlice,30', { headers: true })
  .then((rows) => console.log(rows));

papaparse is designed first and foremost for the browser, with excellent support for file inputs, network streams, and worker threads. It also works in Node.js but shines in frontend apps. It uses a configurable callback system and supports streaming via step or chunk.

// papaparse (browser-friendly)
Papa.parse(fileInput.files[0], {
  header: true,
  step: (row) => console.log("Row:", row.data),
  complete: () => console.log("All done!")
});

// papaparse (Node.js with string)
Papa.parse('name,age\nBob,25', {
  header: true,
  complete: (results) => console.log(results.data)
});

🌐 Environment Support: Where Each Package Runs

  • csv-parser: Node.js only. Relies on Node streams; won’t work in browsers without heavy polyfills.
  • csvtojson: Node.js only. Uses fs module internally; no browser support.
  • fast-csv: Both Node.js and browser (when bundled). Uses standard JavaScript; no Node-specific APIs in core parser.
  • papaparse: Browser-first, but works in Node.js. Optimized for File, Blob, and ReadableStream; handles encoding issues common in user-uploaded files.

If you’re building a frontend app that lets users upload CSVs, papaparse or fast-csv are your only realistic choices. For server-side batch processing, all four work, but csv-parser and fast-csv scale better with large files.

βš™οΈ Configuration and Customization

All packages let you customize delimiters, quote characters, and header handling, but their APIs differ.

csv-parser uses simple options passed to the constructor:

fs.createReadStream('data.csv')
  .pipe(csv({ separator: ';', quote: '"' }))
  .on('data', console.log);

csvtojson uses method chaining:

csv({
  delimiter: "auto",
  quote: '"'
}).fromFile('data.csv').then(console.log);

fast-csv offers a consistent options object across stream and promise modes:

csv.parse({
  delimiter: ',',
  quote: '"',
  headers: true
});

papaparse provides the most flexible config, including dynamic typing, error recovery, and transform functions:

Papa.parse(file, {
  header: true,
  delimiter: ",",
  skipEmptyLines: true,
  transform: (value, field) => field === 'age' ? Number(value) : value
});

Notably, only papaparse supports automatic delimiter detection (delimiter: ""), which is extremely useful when dealing with user-provided files that might use commas, semicolons, or tabs.

πŸ“‰ Memory and Performance Considerations

For small files (<10MB), all parsers perform similarly. But for large datasets, architecture matters:

  • Streaming parsers (csv-parser, fast-csv in stream mode, papaparse with step) process one row at a time, keeping memory usage low.
  • Buffered parsers (csvtojson, fast-csv in promise mode, papaparse without step) load everything into RAM first.

Example: parsing a 500MB CSV

  • βœ… Good: csv-parser or fast-csv streams β€” memory stays flat.
  • ❌ Risky: csvtojson β€” may crash Node.js with out-of-memory errors.
  • ⚠️ Depends: papaparse β€” use step for streaming, avoid complete for huge files.

In the browser, papaparse’s web worker support (worker: true) prevents UI freezing during large parses β€” a feature none of the others offer.

πŸ› οΈ Error Handling and Robustness

csv-parser emits an 'error' event on malformed input.

stream.on('error', (err) => console.error('Parse error:', err));

csvtojson passes errors to the callback or rejects the promise.

fast-csv throws errors in promise mode or emits 'error' in stream mode.

papaparse provides the most detailed error reporting, including line numbers and partial results:

Papa.parse(file, {
  error: (error, file) => {
    console.error(`Error on line ${error.row}:`, error.message);
  },
  complete: (results) => {
    // results.errors contains all parse errors
    console.log(`${results.errors.length} errors found`);
  }
});

This makes papaparse especially valuable in user-facing apps where you need to show helpful feedback like β€œLine 42 has unmatched quotes.”

πŸ” Writing CSV (Not Just Reading)

Only two of these libraries support generating CSV, not just parsing:

  • fast-csv includes a full format() API:
const { writeToString } = require('fast-csv');

writeToString([{ name: 'Alice', age: 30 }], { headers: true })
  .then(console.log); // "name,age\nAlice,30"
  • papaparse offers Papa.unparse():
const csvString = Papa.unparse([
  { name: 'Bob', age: 25 }
]);
console.log(csvString); // "name,age\nBob,25"

csv-parser and csvtojson are read-only.

πŸ“‹ Summary Table

Featurecsv-parsercsvtojsonfast-csvpapaparse
EnvironmentNode.js onlyNode.js onlyNode + BrowserBrowser + Node
Streamingβœ… (streams)βŒβœ… (streams/promise)βœ… (step/chunk)
Auto-delimiterβŒβŒβŒβœ…
Web WorkersβŒβŒβŒβœ…
CSV GenerationβŒβŒβœ…βœ…
Memory Efficientβœ…βŒβœ… (in stream mode)βœ… (with step)
Detailed ErrorsBasicBasicBasicβœ… (line numbers)

πŸ’‘ When to Use Which

  • Building a browser app with file uploads? β†’ papaparse. It handles real-world CSV quirks, gives great error messages, and won’t freeze the UI.
  • Processing huge CSVs on a Node server? β†’ csv-parser or fast-csv (stream mode). Both keep memory low and scale well.
  • Need to both read and write CSV in Node or browser? β†’ fast-csv. It’s the only one besides papaparse that writes CSV, and it works everywhere.
  • Quick script for small CSV files in Node? β†’ csvtojson is simple, but avoid it for anything over 10MB.

Choose based on where your code runs, how big your data is, and whether you need to generate CSV too. Don’t pick a Node-only tool for frontend work β€” and don’t load a 1GB file into memory just because the API looks simpler.

How to Choose: csv-parser vs csvtojson vs fast-csv vs papaparse

  • csv-parser:

    Choose csv-parser if you're working exclusively in Node.js and need to process very large CSV files efficiently using streams. It's lightweight and integrates naturally with Node's stream pipeline, but it doesn't support browsers, CSV generation, or advanced features like auto-delimiter detection.

  • csvtojson:

    Choose csvtojson for simple, small-scale CSV parsing tasks in Node.js where ease of use outweighs performance concerns. It loads entire files into memory, so avoid it for files larger than 10–20 MB or in memory-constrained environments. It lacks browser support and CSV writing capabilities.

  • fast-csv:

    Choose fast-csv if you need a versatile solution that works in both Node.js and browsers and supports both parsing and generating CSV. It offers streaming for memory efficiency and a consistent API across environments, making it ideal for full-stack applications that handle CSV on both client and server.

  • papaparse:

    Choose papaparse for browser-based applications that accept user-uploaded CSV files. It excels at handling real-world CSV inconsistencies, provides detailed error reporting with line numbers, supports web workers to prevent UI freezes, and includes CSV generation via unparse(). It also works in Node.js but is optimized for frontend use.

README for csv-parser

csv-parser

tests cover size

Streaming CSV parser that aims for maximum speed as well as compatibility with the csv-spectrum CSV acid test suite.

csv-parser can convert CSV into JSON at at rate of around 90,000 rows per second. Performance varies with the data used; try bin/bench.js <your file> to benchmark your data.

csv-parser can be used in the browser with browserify.

neat-csv can be used if a Promise based interface to csv-parser is needed.

Note: This module requires Node v8.16.0 or higher.

Benchmarks

⚑️ csv-parser is greased-lightning fast

β†’ npm run bench

  Filename                 Rows Parsed  Duration
  backtick.csv                       2     3.5ms
  bad-data.csv                       3    0.55ms
  basic.csv                          1    0.26ms
  comma-in-quote.csv                 1    0.29ms
  comment.csv                        2    0.40ms
  empty-columns.csv                  1    0.40ms
  escape-quotes.csv                  3    0.38ms
  geojson.csv                        3    0.46ms
  large-dataset.csv               7268      73ms
  newlines.csv                       3    0.35ms
  no-headers.csv                     3    0.26ms
  option-comment.csv                 2    0.24ms
  option-escape.csv                  3    0.25ms
  option-maxRowBytes.csv          4577      39ms
  option-newline.csv                 0    0.47ms
  option-quote-escape.csv            3    0.33ms
  option-quote-many.csv              3    0.38ms
  option-quote.csv                   2    0.22ms
  quotes+newlines.csv                3    0.20ms
  strict.csv                         3    0.22ms
  latin.csv                          2    0.38ms
  mac-newlines.csv                   2    0.28ms
  utf16-big.csv                      2    0.33ms
  utf16.csv                          2    0.26ms
  utf8.csv                           2    0.24ms

Install

Using npm:

$ npm install csv-parser

Using yarn:

$ yarn add csv-parser

Usage

To use the module, create a readable stream to a desired CSV file, instantiate csv, and pipe the stream to csv.

Suppose you have a CSV file data.csv which contains the data:

NAME,AGE
Daffy Duck,24
Bugs Bunny,22

It could then be parsed, and results shown like so:

const csv = require('csv-parser')
const fs = require('fs')
const results = [];

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('data', (data) => results.push(data))
  .on('end', () => {
    console.log(results);
    // [
    //   { NAME: 'Daffy Duck', AGE: '24' },
    //   { NAME: 'Bugs Bunny', AGE: '22' }
    // ]
  });

To specify options for csv, pass an object argument to the function. For example:

csv({ separator: '\t' });

API

csv([options | headers])

Returns: Array[Object]

options

Type: Object

As an alternative to passing an options object, you may pass an Array[String] which specifies the headers to use. For example:

csv(['Name', 'Age']);

If you need to specify options and headers, please use the the object notation with the headers property as shown below.

escape

Type: String
Default: "

A single-character string used to specify the character used to escape strings in a CSV row.

headers

Type: Array[String] | Boolean

Specifies the headers to use. Headers define the property key for each value in a CSV row. If no headers option is provided, csv-parser will use the first line in a CSV file as the header specification.

If false, specifies that the first row in a data file does not contain headers, and instructs the parser to use the column index as the key for each column. Using headers: false with the same data.csv example from above would yield:

[
  { '0': 'Daffy Duck', '1': 24 },
  { '0': 'Bugs Bunny', '1': 22 }
]

Note: If using the headers for an operation on a file which contains headers on the first line, specify skipLines: 1 to skip over the row, or the headers row will appear as normal row data. Alternatively, use the mapHeaders option to manipulate existing headers in that scenario.

mapHeaders

Type: Function

A function that can be used to modify the values of each header. Return a String to modify the header. Return null to remove the header, and it's column, from the results.

csv({
  mapHeaders: ({ header, index }) => header.toLowerCase()
})
Parameters

header String The current column header.
index Number The current column index.

mapValues

Type: Function

A function that can be used to modify the content of each column. The return value will replace the current column content.

csv({
  mapValues: ({ header, index, value }) => value.toLowerCase()
})
Parameters

header String The current column header.
index Number The current column index.
value String The current column value (or content).

newline

Type: String
Default: \n

Specifies a single-character string to denote the end of a line in a CSV file.

quote

Type: String
Default: "

Specifies a single-character string to denote a quoted string.

raw

Type: Boolean

If true, instructs the parser not to decode UTF-8 strings.

separator

Type: String
Default: ,

Specifies a single-character string to use as the column separator for each row.

skipComments

Type: Boolean | String
Default: false

Instructs the parser to ignore lines which represent comments in a CSV file. Since there is no specification that dictates what a CSV comment looks like, comments should be considered non-standard. The "most common" character used to signify a comment in a CSV file is "#". If this option is set to true, lines which begin with # will be skipped. If a custom character is needed to denote a commented line, this option may be set to a string which represents the leading character(s) signifying a comment line.

skipLines

Type: Number
Default: 0

Specifies the number of lines at the beginning of a data file that the parser should skip over, prior to parsing headers.

maxRowBytes

Type: Number
Default: Number.MAX_SAFE_INTEGER

Maximum number of bytes per row. An error is thrown if a line exeeds this value. The default value is on 8 peta byte.

strict

Type: Boolean
Default: false

If true, instructs the parser that the number of columns in each row must match the number of headers specified or throws an exception. if false: the headers are mapped to the column index less columns: any missing column in the middle will result in a wrong property mapping! more columns: the aditional columns will create a "_"+index properties - eg. "_10":"value"

outputByteOffset

Type: Boolean
Default: false

If true, instructs the parser to emit each row with a byteOffset property. The byteOffset represents the offset in bytes of the beginning of the parsed row in the original stream. Will change the output format of stream to be { byteOffset, row }.

Events

The following events are emitted during parsing:

data

Emitted for each row of data parsed with the notable exception of the header row. Please see Usage for an example.

headers

Emitted after the header row is parsed. The first parameter of the event callback is an Array[String] containing the header names.

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('headers', (headers) => {
    console.log(`First header: ${headers[0]}`)
  })

Readable Stream Events

Events available on Node built-in Readable Streams are also emitted. The end event should be used to detect the end of parsing.

CLI

This module also provides a CLI which will convert CSV to newline-delimited JSON. The following CLI flags can be used to control how input is parsed:

Usage: csv-parser [filename?] [options]

  --escape,-e         Set the escape character (defaults to quote value)
  --headers,-h        Explicitly specify csv headers as a comma separated list
  --help              Show this help
  --output,-o         Set output file. Defaults to stdout
  --quote,-q          Set the quote character ('"' by default)
  --remove            Remove columns from output by header name
  --separator,-s      Set the separator character ("," by default)
  --skipComments,-c   Skip CSV comments that begin with '#'. Set a value to change the comment character.
  --skipLines,-l      Set the number of lines to skip to before parsing headers
  --strict            Require column length match headers length
  --version,-v        Print out the installed version

For example; to parse a TSV file:

cat data.tsv | csv-parser -s $'\t'

Encoding

Users may encounter issues with the encoding of a CSV file. Transcoding the source stream can be done neatly with a modules such as:

Or native iconv if part of a pipeline.

Byte Order Marks

Some CSV files may be generated with, or contain a leading Byte Order Mark. This may cause issues parsing headers and/or data from your file. From Wikipedia:

The Unicode Standard permits the BOM in UTF-8, but does not require nor recommend its use. Byte order has no meaning in UTF-8.

To use this module with a file containing a BOM, please use a module like strip-bom-stream in your pipeline:

const fs = require('fs');

const csv = require('csv-parser');
const stripBom = require('strip-bom-stream');

fs.createReadStream('data.csv')
  .pipe(stripBom())
  .pipe(csv())
  ...

When using the CLI, the BOM can be removed by first running:

$ sed $'s/\xEF\xBB\xBF//g' data.csv

Meta

CONTRIBUTING

LICENSE (MIT)