Node.js CommonJS (CJS)
The CommonJS distribution is appropriate to Node.js packages which have not yet migrated to ECMAScript modules. It is available in your code with:
- Stream and callback API:
const {parse} = require('csv-parse');
- Sync API:
const {parse} = require('csv-parse/sync');
Additional information are available in the project CommonJS documentation.
Supported Node.js versions
The CommonJS distribution of this package supports the usage of Node.js version 8.3 and above. However, the module path differs depending on your Node.js version.
Internally, the export
property inside the package.json
file declares the csv-parse
and csv-parse/sync
entry points. It exposes the modules of the ./dist/cjs
folder.
It is supported in Node.js 12.16.0+ as an alternative to the main
field. For older versions, the main
field behaves as a fallback to the csv
module. It is transparent. Use require("csv-parse/dist/cjs/sync.cjs")
as an alternative to require("csv-parse/sync")
.
Older versions of this package
In version 2 and below, the module signature was:
const parse = require('csv-parse');
// And
const parse = require('csv-parse/lib/sync');