API Reference

csv-parse

Streaming CSV parser for Node.js that handles quoting, delimiters, headers and large files.

Official Documentation ↗
CompatibilityThis documentation covers version csv-parse v5.x / Node 18 LTS. Check the official docs for the latest API surface.

Installation

npmnpm install csv-parse
pnpmpnpm add csv-parse
yarnyarn add csv-parse

Methods

Overview

csv-parse reads comma-separated data into rows or objects while respecting quoting and escaping rules. Its streaming mode keeps memory flat for files that do not fit in RAM.

Core Methods

Use the streaming parser by piping a readable stream, or the sync parser for in-memory strings. Options control delimiter, quote, escape, header mapping, casting and error tolerance.

Usage Notes

Pipe large files through a stream and process rows incrementally. Enable cast for typed values, and always validate row shape because CSV has no enforced schema.

Common Pitfalls

Wrong delimiter or quote settings silently misalign columns. Streaming errors are emitted asynchronously, so attach an error handler. Casting uses heuristics that may misfire on values like ZIP codes, so review type inference.

FAQ

What is the difference between csv-parse and csv-parse/sync?
The default export is streaming and asynchronous, ideal for large files. The sync variant reads the whole input and returns an array, which is convenient for small or test data.
Why are my columns shifted?
Inconsistent quoting or an unexpected delimiter shifts fields. Set the correct delimiter, quote and escape options, and enable relax_column_count to detect malformed rows.
How are headers handled?
With columns: true the first row becomes object keys. An array value renames columns, and a function transforms header names, which helps normalize messy exports.