The `csv-generate` package, currently at version 4.5.1, is a flexible JavaScript library for generating random CSV strings and JavaScript objects. It implements the Node.js `stream.Readable` API, making it suitable for scalable data generation in both Node.js and browser environments. As a component of the broader `node-csv` project, it benefits from a stable API and active maintenance, with new releases typically aligned with the entire CSV ecosystem. Key differentiators include its adherence to the stream API for efficient memory usage with large datasets, the ability to produce random or pseudo-random data based on a seed for idempotent generation, and support for user-defined value generation across various data types (integers, booleans, dates, etc.). It can output either raw CSV strings or structured JavaScript objects (arrays) depending on configuration.
npm install csv-generateVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `csv-generate` to create a stream that outputs a fixed number of pseudo-random CSV records as JavaScript arrays, handling events for data consumption and errors.
Always include `{ objectMode: true }` in the options object passed to `generate()` if you expect structured data records.Always register an error listener on the stream, for example: `.on('error', (err) => console.error(err));`.When piping streams, Node.js handles backpressure automatically. If consuming manually with `.on('data')` or `.on('readable')`, check `writableStream.write(chunk)` return value and call `readableStream.pause()` when `false`, resuming with `writableStream.once('drain', () => readableStream.resume())`.Ensure you are using named import syntax: `import { generate } from 'csv-generate';` and call it directly as a function: `generate({...});`.Add an error handler to your stream: `generate(...).on('error', (err) => console.error('Stream error:', err));`.Pass `{ objectMode: true }` in the options object when calling `generate()`: `generate({ objectMode: true, ... });`.No dependency data recorded yet.