

You will use the csv-parse module to parse a CSV file and the csv-stringify module to write data to a CSV file. The command installs all four modules that are part of the node-csv package: csv-generate, csv-parse, csv-stringify, and stream-transform. The node-csv module is a collection of modules that allows you to parse and write data to a CSV file. With the directory initialized as an npm project, you can now install the necessary dependencies: node-csv and node-sqlite3.Įnter the following command to install node-csv:

This command creates a package.json with default values that you can change anytime. The -y option notifies npm init to say “yes” to all the prompts. Next, initialize the directory as an npm project using the npm init command: To get started, make a directory called csv_demo and navigate into the directory: You will also download a CSV dataset from Stats NZ, which contains international migration data in New Zealand. In this section, you will create the project directory and download packages for your application. Step 1 - Setting Up the Project Directory See How To Work with Files Using Streams in Node.js. See How To Write and Run Your First Program in Node.js.įamiliarity with Node.js streams. Knowledge on how to use SQLite is helpful and can be learned in steps 2-7 of the installation guide.įamiliarity with writing a Node.js program.

SQLite installed on your local or server environment, which you can install by following step 1 in How To Install and Use SQLite on Ubuntu 20.04.

Follow How to Install Node.js and Create a Local Development Environment to install Node.js. Node.js installed on your local or server environment. You will also retrieve data from the database, parse it with node-csv, and use Node.js streams to write it to a CSV file in chunks. You will modify the program to move data parsed from the CSV file into a SQLite database. In this tutorial, you will use the node-csv module to read a CSV file using Node.js streams, which lets you read large datasets without consuming a lot of memory. Node.js has many modules that can work with CSV files, such as node-csv, fast-csv, and papaparse. Because CSV is a plain-text file, any programming language can parse and write to a CSV file. Most spreadsheet programs and databases can export and import CSV files. The CSV file uses a comma delimiter to separate values in table cells, and a new line delineates where rows begin and end. IntroductionĪ CSV is a plain text file format for storing tabular data. The author selected Society of Women Engineers to receive a donation as part of the Write for DOnations program.
