API Reference

csv-stringify

CSV stringifier with column control, headers, quoting, and streaming for Node.js.

Official Documentation ↗
CompatibilityThis documentation covers version v6. Check the official docs for the latest API surface.

Installation

npmnpm install csv-stringify

Methods

csv-stringify converts arrays or objects into CSV text, either buffered or as a stream.

Key Features

  • Header row generation from object keys
  • Quoting and delimiter configuration
  • Stream transform for large outputs

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Security

Official security statements captured from the package documentation:

  • escape_formulas 选项用于防御 CSV 注入 — “- escape_formulas (boolean) Since version 6.3.0 Escape values that start with =, +, -, @, \t, or \r with ' and defend against CSV injection attacks.” (source: https://csv.js.org/stringify/options/, fetched 2026-11-08T17:48:10.000Z)

API reference evidence

Fetched from official sources on 2026-11-08T17:48:10.000Z via WebFetch https://csv.js.org/stringify/api/sync/.

FAQ

Which option enables headers?
Set header: true to emit a header row; the labels come from object keys or the columns option headers.
How do I protect against CSV injection?
Prefix cells beginning with =, +, -, or @ when they are user-controlled, since spreadsheets may interpret them as formulas.
Can I stream a huge result set?
Yes. Use the Stringifier transform and pipe records into it so only a small buffer is held at a time.