Registry / data / fast-csv

fast-csv

JSON →
library1.3.4jsnpmunverified

fast-csv is a robust and high-performance CSV parser and writer library for Node.js, designed to handle large datasets efficiently. The current stable version is 5.0.5. It generally maintains a steady release cadence, with minor updates and bug fixes appearing every few months, and major versions released less frequently, typically when significant API changes or new features warrant it. Key differentiators include its streaming API, which allows for processing CSV data without buffering the entire file into memory, making it suitable for very large files. It supports both parsing (reading) and formatting (writing) CSV data, offering flexible configuration options for headers, delimiters, quotes, and escape characters, and ships with full TypeScript type definitions.

npm install fast-csv
INSTALL
IMPORT
SIG · FAST-CSV
F
fast-csv
datajavascriptv1.3.4
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseFile
✓ import { parseFile } from 'fast-csv';
✗ const { parseFile } = require('fast-csv');
ESM imports are recommended for modern Node.js projects. CommonJS `require` still works.
format
✓ import { format } from 'fast-csv';
✗ import format from 'fast-csv';
The `format` function is a named export, not a default export.
FormatterOptions
✓ import type { FormatterOptions } from 'fast-csv';
Import types separately using `import type` for clarity and better tree-shaking with TypeScript.

Demonstrates reading a CSV file, modifying its content, and then writing the modified data to a new CSV file using streaming APIs.

import { parseFile, format } from 'fast-csv'; import * as fs from 'node:fs'; const inputFilePath = './data.csv'; const outputFilePath = './output.csv'; // Create a dummy CSV file for demonstration fs.writeFileSync(inputFilePath, 'header1,header2\nvalue1,value2\nvalue3,value4'); const rows: { header1: string; header2: string }[] = []; parseFile(inputFilePath, { headers: true }) .on('error', error => console.error('Error parsing CSV:', error)) .on('data', row => rows.push(row)) .on('end', (rowCount: number) => { console.log(`Parsed ${rowCount} rows.`); console.log('Original Rows:', rows); // Modify data and write to a new CSV const modifiedRows = rows.map(row => ({ header1: `MODIFIED_${row.header1}`, header2: `${row.header2}_END` })); const ws = fs.createWriteStream(outputFilePath); format(modifiedRows, { headers: true }) .on('error', error => console.error('Error writing CSV:', error)) .pipe(ws) .on('end', () => console.log('CSV file successfully written to output.csv')); });
Debug
Known issues
breakingVersion 5.0.0 introduced breaking changes related to internal dependencies and potentially minor API adjustments. Specifically, `@types/node` was removed from package dependencies, implying users should manage their `@types/node` installation if required for their environment.
fix
Ensure `@types/node` is installed as a dev dependency (`npm install --save-dev @types/node`) if you are using TypeScript and targeting Node.js APIs directly in your project.
affects: >=5.0.0
gotchaWhen parsing CSVs without explicit `headers: true`, the data will be returned as an array of strings per row. If `headers: true` is used, data will be returned as objects where keys correspond to header names. Mixing these assumptions can lead to runtime errors.
fix
Always explicitly set the `headers` option in `parseFile` or `parseStream` to `true` if your CSV has headers and you want object-based rows, or to `false` if you expect array-based rows.
affects: >=4.0.0
gotchaThe `fast-csv` parser uses an event-driven streaming approach. Forgetting to attach 'error' event listeners to the parser stream can lead to unhandled promise rejections or uncaught exceptions, silently terminating your application when malformed data or I/O errors occur.
fix
Always include an `.on('error', errorHandler)` listener in your parsing and formatting pipelines to gracefully handle issues like file read errors, invalid CSV formats, or write errors.
affects: >=4.0.0
gotchaDefault quoting behavior for the formatter can sometimes lead to unexpected results if fields contain delimiters or newlines but are not explicitly quoted. The formatter attempts to be smart about quoting, but specific scenarios might require overriding this.
fix
For precise control over quoting, refer to the `quote` and `quoteColumns` options in the `FormatterOptions`. If you want to force quoting for all fields, you might need a custom transform or specific formatter configuration.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'pipe')
Attempting to call `.pipe()` on a `fast-csv` stream that hasn't been properly initialized or is not a Writable stream.
fix
Ensure the `format()` function returns a writable stream, usually by providing an array of data. When writing to a file, ensure `fs.createWriteStream()` is correctly called and that the `format` function is called with the data to be written.
Error: Unhandled 'error' event.
A stream operation (parsing or formatting) encountered an error (e.g., malformed CSV, file read/write error) but no error handler was attached.
fix
Add an `.on('error', (err) => console.error(err))` listener to your `parseFile`, `parseStream`, `format`, or `pipe` chain to catch and handle errors gracefully.
TS2305: Module '"fast-csv"' has no exported member 'formatDefault'.
Trying to import `formatDefault` or other symbols that are not explicitly exported by the `fast-csv` module, or using an incorrect import style.
fix
Check the official documentation or type definitions (`.d.ts` files) for the correct named exports. For example, `format` is a named export, not `formatDefault` or a default export.
Upgrade
Version history
1.3.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
fast-csv — npm install fast-csv · libregistry