# How to read a CSV file with Node.js

> Learn how to read a CSV file with Node.js using the neat-csv package, which wraps csv-parser in a simple async/await interface returning an array of objects.

Author: Flavio Copes | Published: 2019-12-15 | Canonical: https://flaviocopes.com/node-read-csv/

Many different [npm](https://flaviocopes.com/npm/) modules let you read from a CSV file.

Most of them are based on [streams](https://flaviocopes.com/nodejs-streams/), like [`csv-parser`](https://github.com/mafintosh/csv-parser) or [`node-csv`](https://csv.js.org/).

Those are great to deal with CSV in a production system.

I like to keep things simple when I don't have performance in mind. For example, for a one-time parsing of CSV that I had to do to consolidate my backend systems.

To do so, I used [`neat-csv`](https://github.com/sindresorhus/neat-csv), a package that exposes the `csv-parser` functionality to a simple async/await interface.

Install it using `npm install neat-csv` and require it in your app:

```js
const neatCsv = require('neat-csv');
```

then load the CSV from the filesystem and invoke neatCsv passing the content of the file:

```js
const fs = require('fs')

fs.readFile('./file.csv', async (err, data) => {
  if (err) {
    console.error(err)
    return
  }
  console.log(await neatCsv(data))
})
```

Now you can start doing whatever you need to do with the data, which is formatted as a [JavaScript](https://flaviocopes.com/javascript/) array of objects.

If you need to convert that array to JSON or back to CSV without writing a script, I built a free [JSON ↔ CSV converter](https://flaviocopes.com/tools/json-csv/) for quick one-off jobs.
