Get Started with CSVParse for Node.js (csv-parse npm package)

Published: (February 13, 2026 at 04:07 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Installation

npm i csv-parse

Example CSV (data.csv)

name,age,email
Alex,33,alex@example.com
Bekky,20,bekky@example.com
Carl,27,carl@example.com

Parsing CSV with Streams

import fs from 'node:fs';
import { parse } from 'csv-parse';

const records = [];

fs.createReadStream('path/data.csv')
  .pipe(
    parse({
      columns: true,          // use first row as header
      skip_empty_lines: true,
    })
  )
  .on('data', (row) => {
    records.push(row);
  })
  .on('error', (err) => {
    console.error(err.message);
  })
  .on('end', () => {
    console.log(records);
  });

Result

[
  { "name": "Alex", "age": "33", "email": "alex@example.com" },
  { "name": "Bekky", "age": "20", "email": "bekky@example.com" },
  { "name": "Carl", "age": "27", "email": "carl@example.com" }
]

Parse API

parse(input, options, callback);
  • input: string or Buffer containing CSV data.
  • options (optional): parsing rules, e.g., { columns: true, delimiter: ',' }.
  • callback: (err, records) – receives an error (if any) and the parsed records.

Performance Recommendations

  • Use fs.createReadStream() to stream large files piece by piece, avoiding loading the entire file into memory.
  • For small files (≤ 5 MB), fs.readFile() is acceptable.
0 views
Back to Blog

Related posts

Read more »

Inertia.js Silently Breaks Your App

TL;DR After weeks in a production Laravel 12 + React 19 + Inertia v2 app, I repeatedly hit failure modes that were expensive to diagnose: overlapping visit can...