CSVParse for Node.js

IssuesGitHub

Using pipe to connect multiple streams

Part of the Stream API, the pipe function is a precious tool used to wire multiple streams. The function is meant to connect a stream.Readable source to a stream.Writable destination.

The pipe example reads a file, parses its content, transforms it and print the result to the standard output.

This example is available with the command node samples/recipe.pipe.js.

import { parse } from 'csv-parse';
import { generate } from 'csv-generate';
import { transform } from 'stream-transform';

const generator = generate({
  length: 20
});
const parser = parse({
  delimiter: ':'
});
const transformer = transform((record, callback) => {
  setTimeout(() => {
    callback(null, record.join(' ')+'\n');
  }, 500);
}, {
  parallel: 5
});
generator.pipe(parser).pipe(transformer).pipe(process.stdout);

About

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