CSVStringify for Node.js


Node.js Stream API

The main module of the package implements the native Node.js transform stream which is both readable and writable.

This is the recommended approach if you need a maximum of power. It ensures scalability by treating your data as a stream from the source to the destination.

The signature is const stream = stringify([options]).

The stream example write 2 records and register multiple events to read the generated CSV output and get notified when the serialisation is finished.

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

const data = [];
// Initialize the stringifier
const stringifier = stringify({
  delimiter: ':'
// Use the readable stream api to consume CSV data
stringifier.on('readable', function(){
  let row;
  while((row = stringifier.read()) !== null){
// Catch any error
stringifier.on('error', function(err){
// When finished, validate the CSV output with the expected value
stringifier.on('finish', function(){
    'root:x:0:0:root:/root:/bin/bash\n' +
// Write records to the stream
stringifier.write([ 'root','x','0','0','root','/root','/bin/bash' ]);
stringifier.write([ 'someone','x','1022','1022','','/home/someone','/bin/bash' ]);
// Close the writable stream

After cloning the project repository, run this example with the command node samples/api.stream.js.


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