CSVParse for Node.js

IssuesGitHub

Callback API

The signature is parse(data, [options], callback).

The callback example takes the CSV string in the first argument (input), options in the second argument, and a user callback in the third argument. The callback receives any error thrown by the CSV parser in the first parameter (err), or an array of records in the second argument (output). It returns an array.

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

const input = '#Welcome\n"1","2","3","4"\n"a","b","c","d"';
parse(input, {
  comment: '#'
}, function(err, records){
  assert.deepStrictEqual(
    records,
    [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ]
  );
});

About

The Node.js CSV project is an open source product hosted on GitHub and developed by Adaltas.