

This parser is assigned to a constant variable and we simply print its contents out for brevity's sake: [ĭescription: 'Amount owed to employes for hours not yet paid'ĭescription: 'Cost of occupied rented facilities during accounting period'

This object literal contains options for creating the parser (we've set columns to true). Then, we can create a parser which takes in the file contents as the first argument and an object literal as the second. Then, we're creating an async function, in which we retrieve the contents of the file by awaiting the response of the readFile() function. Var parser = parse() Īgain, we're importing the fs module and the Sync API from the csv-parse module. Let's create a file, called index.js and construct a parser: var fs = require( 'fs') We'll be covering the stream + callback API and the Sync API. The csv-parse package provides multiple approaches for parsing CSV files - using callbacks, a stream + callback as well as the Sync and Async API. To read CSV files, we’ll be using the csv-parse package from node-csv. Rent expense,560,Expenses,Cost of occupied rented facilities during accounting period Wages Payable,220,Liabilities,Amount owed to employes for hours not yet paid We'll be working with a CSV file with these contents: Account Name,Account Code,Type,Description Note: Although the suite is called node-csv - the relevant NPM package is actually called csv.
