API Reference

fast-csv

CSV parser and formatter for Node.js with stream-based read, write and validation hooks.

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

Installation

npmnpm install fast-csv
pnpmpnpm add fast-csv
yarnyarn add fast-csv

Methods

Overview

fast-csv offers separate parser and formatter streams, so CSV data can flow through a Node pipeline with transformation and validation at each stage. It handles headers, quoting and custom delimiters.

Core Methods

parse consumes a readable or string and emits row objects. format produces CSV text from rows. Options configure headers, delimiters and a validate predicate for per-row rules.

Usage Notes

Prefer streaming parse into format for large conversions, and attach error and end handlers to detect truncation. Use validate to reject bad rows with a clear reason.

Common Pitfalls

Ignoring back-pressure by writing faster than the destination consumes data can balloon memory. Header mismatches silently drop or mislabel columns, so verify the first rows. Errors must be handled or the stream hangs.

FAQ

Can fast-csv read and write in one pipeline?
Yes. You can pipe a parse stream into a format stream to transform CSV to CSV, inserting mapping or filtering between them. This keeps memory bounded for large files.
How are headers configured?
Pass headers: true to use the first row as keys, or an array to rename columns. Format uses writeHeaders to emit a header row on output.
What about malformed rows?
The parser emits an error for structurally invalid rows unless you relax the option. The validate hook lets you enforce business rules and fail with a descriptive message.