CSV - love it or hate it, it's a part of many businesses and how they operate. These comma-separated values come in the form of a text file with a specific format that allows for data to be translated into a tabulated structure when imported into spreadsheet software and apps such as Excel and Google Sheets. These table-based reports are often used by analysts, accountants, commercial, and marketing to view, add, and manipulate.
As developers, a majority of us work primarily with JSON, making CSV an incompatible dataset. We cannot easily filter it in its raw form or hook into the data the way we can with JSON.
If you're about to build CSV import functionality into your app yourself. First be sure to check out our product UseCSV first. UseCSV is an all-in-one CSV import product that gives you a delightful CSV importer experience for your users. All you have to do is drop-in the UseCSV JS library, and create a webhook endpoint to receive uploads. This takes away all the headaches of building CSV import functionality in-house. Grab a free developer account here.
fast-csv is a CSV parser and formatter that combines two other popular packages (
@fast-csv/parse) together to form a single package for node.js. It has grown dramatically over the past few years from 0 to approximately 153k downloads per week.
fast-csv is also actively maintained with monthly updates and great documentation.
fast-csv include CSV formatting, parsing, flexible formatting, and parsing options.
fast-csv, use the following command:
npm i -S fast-csv
2. xlsx - SheetJS
xlsx , also known as
The free version is intensely popular with more than a quarter-million downloads each week and over 100 contributors to the library. The documentation is not as extensive as
fast-csv but adequate enough to get you started and do what you need.
xlsx also comes demo directories that give sample implementation into major frameworks and libraries such as Angular, Ionic, knockout, meteor, React, React Native, Vue, and nodeJS.
xlsx, use the following command:
npm install xlsx
papaparse is an MIT license and open-sourced CSV parser library with great documentation and easy-to-use implementations. It has zero dependencies and can work as a stand-alone library that is able to parse CSV files directly in a local environment or stream larger files.
There is also the ability to pause, resume, and abort data transfers and CSV parsing, convert numbers and booleans into types.
papaparse was created with NodeJS in mind, allowing for readable streams instead of just accepting data via a file.
papaparse, use the following command:
npm install papaparse
It's one thing to go from CSV to JSON - but what about JSON to CSV? The ability to export CSV can be achieved with
json-2-csv library that lets you convert JSON and CSV data in both directions.
json-2-csv also supports sub-documents, custom ordering of columns, and the ability to re-generate JSON documents that were used to generate the CSV. Its ability to handle nesting is fairly extensive and function.
json-2-csv, use the following command:
npm install json-2-csv
csvtojson is a library that is modular and comprehensive in its handling of CSV. The library is to parse CSV to JSON or column arrays. In addition to being a library, it can also be used as a command line tool or directly in the browser for quick and targeted parsing.
csvtojson is built on
bluebird (a promise library),
lodash (utility library), and
strip-bom (a UTF-8 byte order mark from a string) in order to deliver streaming capabilities and enable asynchronous integrations.
csvtojson, use the following command:
npm install csvtojson
csv-parser is a library that lets you convert CSV to JSON at the rate of around 90,000 rows per second. It also has the ability to convert CSV to JSON via the command line using
csv-parser [filename?] [options]
The library is MIT licensed and is downloaded at the rate of approximately 100k per week. With the help of browserify,
csv-parser can also be used in the browser.
csv-parser, use the following command:
npm install csv-parser
csv is a collection of packages that can be used as stand-alone implementations or together based on the requirements.
csv is the umbrella package that contains four other packages.
csv, use the following command:
npm install csv
The above will also install the following (which can be installed as separate packages if not everything is required):
csv-generate, use the following command:
npm install csv-generate
csv-parse - a reader that allows your app to read CSV strings, buffers, and write objects and arrays. To install
csv-parse, use the following command:
npm install csv-parse
csv-stringify - a stringifier that converts records into CSV text. To install
csv-stringify, use the following command:
npm install csv-stringify
- a simple object transformation framework for nodeJS. To installstream-transform`, use the following command:
npm install stream-transform
nest-csv-parser is a csv-parser wrapper NestJS. This means that all the features and functionality available in
csv-parser will also be available in
nest-csv-parser is generally straightforward and all you have to do is import the module into your NestJS project.
nest-csv-parser, use the following command:
npm i nest-csv-parser
ya-csv is a low-key event based CSV parser created to process large CSV streams. It is designed with zero dependencies, making it highly performant and unreliant on other libraries to make it work. With
ya-csv, you can also configure the separators, quote and escape characters as required.
ya-csv, use the following command:
npm i ya-csv
skipper-csv is a CSV parser adapter created to receive upstreams. It also supports multipart file uploads and starts parsing the CSV as soon as the first chunks are ready. This means that you don't have to wait for the upload to finish before you start parsing - resulting in saved time and faster data parsing.
skipper-csv, use the following command:
npm i skipper-csv
Based on popularity, downloads and GitHub stars, fast-csv, xlsx - SheetJS, papaparse, and json-2-csv are the most popular. These top four libraries make up the majority of downloads and comes to a combined 2+ million downloads and installs.
Want a pre-solved CSV import solution?
Remember, you can add CSV data importing to your app easily with UseCSV. All you have to do is drop in the library to your frontend app, link it up with a webhook to your backend, and your MVP, startup, or SaaS is ready to run. It supports CSV and all excel formats, has a validation rule library, and easily handles large import files.