CSV and object generator

Build Status

This package provides a flexible generator of CSV strings and Javascript objects implementing the Node.js stream.Readable API.

Source code for this project is available on GitHub.

Features includes:

  • random or pseudo-random seed based generation
  • stream.Readable implementation


Run npm install csv to install the full csv module or run npm install csv-generate if you are only interested by the CSV parser.

Use the callback style API for simplicity or the stream based API for scalability.

Callback API


Node.js Stream API

generate([options], callback)

For additionnal usage and example, you may refer to the example page, the "samples" folder and the "test" folder.


Options may include:

  • duration
    Period to run in milliseconds, default to 4 minutes.
  • columns
    Define the number of generated fields and the generation method. If columns is an integer, it corresponds to the number of fields. If it is an array, each element correspond to a field. If the element is a function, the function will generate the field value, if it is a string, it call the registered function of the same name.
  • max_word_length
    Maximum number of characters per word.
  • seed
    Generate idempotent random characters if a number provided
  • length
    Number of lines to read.
  • objectMode
    Whether this stream should behave as a stream of objects. Meaning that stream.read(n) returns a single value instead of a Buffer of size n. Default=false
  • highWaterMark
    The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource. Default=16kb

All options are optional.


Most of the generator is imported from its parent project CSV in a effort to split it between the generator, the parser, the transformer and the stringifier.

Fork me on GitHub