🌐
GitHub
github.com › C2FO › fast-csv
GitHub - C2FO/fast-csv: CSV parser and formatter for node · GitHub
@fast-csv/format - Formatting package, use this if you only need to format files.
Starred by 1.8K users
Forked by 216 users
Languages   TypeScript 99.0% | JavaScript 1.0%
🌐
C2fo
c2fo.github.io › fast-csv › docs › formatting › methods
Methods | Fast-CSV
Formats the rows and returns a Promise that will resolve with the CSV content as a Buffer.
Discussions

Fastest csv-formatter library
I make and use CSV-to-something and something-to-CSV parsers all the time for genomics data, and processing billions of lines with a plain object to string transform is fast. You don't need a parser, you just need a formatter, right? So just consume the object stream and add a transform stream (using through2), and in the transform you consume your objects from MongoDB and emit lines of CSV. Do a little benchmarking on whether it's quicker to use an array map with join. I often just do a string interpolation. By far the slowest part will be consuming Mongo JSON. Might want to try a BSON stream or protobuf for faster parsing. Then pump (using pump) the streams together (e.g. pump(process.stdin, mycsvfunc, process.stdout)) and you have the fastest generalised conversion setup you can do in node, and it works with Unix pipes so you can do stupid parallelization by splitting etc. More on reddit.com
🌐 r/node
24
34
August 16, 2020
Csv vs. Json - which is better to read data from?

It's worth pointing out that CSV is a lot less standardized than JSON. While there's RFC 4180, in the real world you'll find a lot of variations from that.

I've dealt with reading and writing files containing millions of records of data as CSV, and I very much doubt speed of CSV vs JSON parsing will be a bottleneck for anything you're doing.

More on reddit.com
🌐 r/golang
19
2
February 21, 2016
Fastest csv parser for Node?

I’ve had good luck with Papa Parse https://www.papaparse.com/

More on reddit.com
🌐 r/node
13
31
August 25, 2018
How to Optimize Large CSV Processing?
You should try loading the csv with polars. Is not much different than pandas, but faster and since you need to drop the duplicates, the function is simple https://docs.pola.rs/api/python/dev/reference/dataframe/api/polars.DataFrame.unique.html After that you can export to pandas since you are more familiar with it. More on reddit.com
🌐 r/learnpython
19
10
October 24, 2024
🌐
npm
npmjs.com › package › @fast-csv › format
fast-csv/format
May 6, 2026 - fast-csv formatting module. Latest version: 5.0.7, last published: 2 months ago. Start using @fast-csv/format in your project by running `npm i @fast-csv/format`. There are 123 other projects in the npm registry using @fast-csv/format.
      » npm install @fast-csv/format
    
Published   May 06, 2026
Version   5.0.7
🌐
npm
npmjs.com › package › fast-csv
fast-csv - npm
May 6, 2026 - Package that combines both @fast-csv/format and @fast-csv/parse into a single package.
      » npm install fast-csv
    
Published   May 06, 2026
Version   5.0.7
🌐
DEV Community
dev.to › chriscmuir › fast-csv-for-csv-files-21a1
fast-csv for CSV files - DEV Community
March 6, 2021 - In looking at the feature set, fast-csv is comprised of 'parse' and 'format' routines for ingesting and transforming CSV files. It also supports streams for fast processing of large files.
🌐
C2fo
c2fo.github.io › fast-csv
Fast-CSV | Fast-CSV
CSV Parser and Formatter · Get Started · Built on top of the Node.js Stream API, so you can work with APIs you are familiar with. Out of the box formatting and parsing of any delimiter separated file.
🌐
C2fo
c2fo.github.io › fast-csv › docs › formatting › examples
Examples | Fast-CSV
The writeHeaders option can be useful when appending to a csv to prevent writing headers twice. See the append example · If writeHeaders is set to false, headers is set to true, and your rows are arrays, the first row will not be written. In this example the auto discovered headers are not written. TypeScript · JavaScript · Output · Copy · import { format } from '@fast-csv/format'; const csvStream = format({ headers: true, writeHeaders: false }); csvStream.pipe(process.stdout).on('end', () => process.exit()); csvStream.write({ header1: 'value1a', header2: 'value2a' }); csvStream.write({ header1: 'value1a', header2: 'value2a' }); csvStream.write({ header1: 'value1a', header2: 'value2a' }); csvStream.write({ header1: 'value1a', header2: 'value2a' }); csvStream.end(); In this example the headers are provided to specify order of columns but they are not written.
🌐
Snyk
snyk.io › advisor › fast-csv › functions › fast-csv.format
How to use the fast-csv.format function in fast-csv | Snyk
const fs = require('fs'); const path = require('path'); const csv = require('fast-csv'); const User = require('./models/user'); fs.createReadStream(path.resolve(__dirname, 'assets', 'snake_case_users.csv')) .pipe(csv.parse({ headers: true })) // pipe the parsed input into a csv formatter .pipe(csv.format({ headers: true })) // Using the transform function from the formatting stream .transform((row, next) => { User.findById(row.id, (err, user) => { if (err) { return next(err); } return next(null, { id: row.id, firstName: row.first_name, lastName: row.last_name, address: row.address, // properties from user isVerified: user.isVerified, hasLoggedIn: user.hasLoggedIn, age: user.age, });
Find elsewhere
🌐
C2fo
c2fo.github.io › fast-csv › docs › introduction › getting-started
Getting Started | Fast-CSV
Fast-csv is library for parsing and formatting CSVs or any other delimited value file in node.
🌐
GitHub
github.com › C2FO › fast-csv › blob › main › documentation › docs › formatting › examples.mdx
fast-csv/documentation/docs/formatting/examples.mdx at main · C2FO/fast-csv
const { format } = require('@fast-csv/format'); const stream = format({ delimiter: '\t' }); stream.pipe(process.stdout); stream.write(['a', 'b']); stream.write(['a1', 'b1']); stream.write(['a2', 'b2']); stream.end();
Author   C2FO
🌐
GitHub
github.com › C2FO › fast-csv › blob › main › README.md
fast-csv/README.md at main · C2FO/fast-csv
@fast-csv/format - Formatting package, use this if you only need to format files.
Author   C2FO
🌐
CodeSandbox
codesandbox.io › examples › package › @fast-csv › format
fast-csv/format examples
Use this online @fast-csv/format playground to view and fork @fast-csv/format example apps and templates on CodeSandbox.
🌐
FastCSV
fastcsv.org
Welcome to FastCSV | FastCSV
Among all actively maintained CSV libraries for Java, FastCSV is the most popular, according to GitHub stars. Don’t forget to leave a ⭐ on GitHub if you like FastCSV! ... This selected benchmark is based on the Java CSV library benchmark suite. ... Reading and writing perfectly formatted CSV ...
🌐
C2fo
c2fo.github.io › fast-csv › docs › introduction › example
Quick Examples | Fast-CSV
Quick examples of parsing and formatting. TypeScript Source · Javascript Source · TypeScript · JavaScript · Output · Copy · import * as csv from 'fast-csv'; const csvStream = csv.format({ headers: true }); csvStream.pipe(process.stdout).on('end', () => process.exit()); csvStream.write({ header1: 'row1-col1', header2: 'row1-col2' }); csvStream.write({ header1: 'row2-col1', header2: 'row2-col2' }); csvStream.write({ header1: 'row3-col1', header2: 'row3-col2' }); csvStream.write({ header1: 'row4-col1', header2: 'row4-col2' }); csvStream.write({ header1: 'row5-col1', header2: 'row5-col2' }); csvStream.end(); TypeScript ·
🌐
Npmdoc
npmdoc.github.io › node-npmdoc-fast-csv › build › apidoc.html
CSV parser and writer
... } this.hasWrittenHeaders = hasHeaders ? false : true; this.includeEndRowDelimiter = !!options.includeEndRowDelimiter, has(options, "consumerTransform") && this.transform(options.consumerTransform); } util.inherits(CsvTransformStream, Transform); extended(CsvTransformStream).extend({ headers: null, headersLength: 0, totalCount: 0, ... ... function format(str, obj) { if (obj instanceof Array) { var i = 0, len = obj.length; //find the matches return str.replace(FORMAT_REGEX, function (m, format, type) { var replacer, ret; if (i < len) { replacer = obj[i++]; } else { //we are out of things to replace with so //just return the match? return m; } if (m === "%s" || m === "%d" || m === "%D") { //fast path!
🌐
LogRocket
blog.logrocket.com › home › a complete guide to csv files in node.js
A complete guide to CSV files in Node.js - LogRocket Blog
August 14, 2024 - You can use @fast-csv/format and @fast-csv/parse for formatting and parsing CSV datasets, respectively.
🌐
C2fo
c2fo.github.io › fast-csv › docs › formatting › options
Options | Fast-CSV
Set to true to include a row delimiter at the end of the csv.
🌐
Snyk
snyk.io › advisor › fast-csv › fast-csv code examples
Top 5 fast-csv Code Examples | Snyk
async function batched () { winston.info(`creating ${totalBatches} csv file `) let currentBatch = 0 let teacherIndex = 1 while (currentBatch &lt; totalBatches) { winston.info(`creating batch ${currentBatch}`) // const csvHeaders = ['username', 'password'] const csvStream = csv.format() const writableStream = fs.createWriteStream(path.join(__dirname, `${currentBatch}-teacherLogins.csv`)) csvStream.pipe(writableStream) // csvStream.write(csvHeaders) let batchIndex = 0 while (batchIndex &lt; batchSize) { batchIndex++ csvStream.write([`teacher${teacherIndex}`, 'password']) teacherIndex++ } csvStream.end() currentBatch++ } }
🌐
Reddit
reddit.com › r/node › fastest csv-formatter library
r/node on Reddit: Fastest csv-formatter library
August 16, 2020 -

Hi everyone! I've been looking for a while for a csv-formatter that matches my criteria, which is pretty simple: to be fast, really fast. Let me add some context to this: I want to format billions of lines as fast as possible. While benchmarking different libraries, I found the best results with fast-csv, which for 200 millions lines of csv, took me about 40 mins, which is way too much for me(if it were something like 10 mins, i would have considered it). I think those libraries are quite slow because of the underlying RegEx implementations of the formatter which scales pretty bad. I am not really looking for a fancy formatter with tons of options, I just want to make sure the output is a valid csv(it can be parsed with a csv-parser by other people). I need a formatter because my data is pretty funky: it contains "," and pretty much any character you can imagine.

In case this information is needed, this is the flow of my app:

  1. Fetch documents from a mongodb(I can't control the format of those documents, I am not the one adding them data so any tweak to them is out of bounds) in batches(because there are tons of them)

  2. Each document has an array field. For each document, I parse that array and for each element of that array i create an in-memory Json(or array, this format doesn't matter, can be whatever) which i'll add to a list.

  3. Once I'm done parsing the array of a document, I give the list to the csv formatter and redirect the output from the formatter to a Readable stream which is part of a ManagedUpload to s3.

As a last resort, I'm considering implementing a formatter which simply does some ifs and puts the field that contain "," between quotation marks.

Top answer
1 of 5
12
I make and use CSV-to-something and something-to-CSV parsers all the time for genomics data, and processing billions of lines with a plain object to string transform is fast. You don't need a parser, you just need a formatter, right? So just consume the object stream and add a transform stream (using through2), and in the transform you consume your objects from MongoDB and emit lines of CSV. Do a little benchmarking on whether it's quicker to use an array map with join. I often just do a string interpolation. By far the slowest part will be consuming Mongo JSON. Might want to try a BSON stream or protobuf for faster parsing. Then pump (using pump) the streams together (e.g. pump(process.stdin, mycsvfunc, process.stdout)) and you have the fastest generalised conversion setup you can do in node, and it works with Unix pipes so you can do stupid parallelization by splitting etc.
2 of 5
4
If you dont need results strictly ordered, you can combine any of the other solutions together run in parallel into a MultipartUpload in s3. Once everything is written you will have a single output file. If each parallel stream is faster than a single upload stream to s3, you can do them as individual ManagedUploads (is that Multipart under the covers?) and do a CopyParts to combine those s3 objects into one. (This last could be overkill, only useful if you a single steam is a bottleneck) Added bonus if you happen to be doing a gzip of them concurrently: gzip files can be safely concatenated together to produce a valid gzip.