Sync API

The sync API expose a function which expect as input a full dataset as text and which returns the full result set as an array or an object.

To summarise, it is a regular direct synchronous call to a function: you pass CSV content and it returns records. Because of its simplicity, this is the recommended approach if you don't need scalability and if your dataset fit in memory. It is much easier to use at the expense of not being scalable.

Import the csv-parse/lib/sync module to use it. The exported function signature is const records = parse(data, [options]).

The synchronous example illustrates how to use the alternative synchronous module. This example is available with the command node samples/module.sync.js.

const parse = require('csv-parse/lib/sync')
const assert = require('assert')

const input = `
"key_1","key_2"
"value 1","value 2"
`
const records = parse(input, {
  columns: true,
  skip_empty_lines: true
})
assert.deepEqual(records, [{ key_1: 'value 1', key_2: 'value 2' }])