Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Node.js Tutorial to Parse & Read Contents of CSV File Using a-csv Library in Javascript

Posted on February 14, 2023

 

 

Welcome folks today in this blog post we will be parsing and reading contents of csv file using a-csv library in javascript. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make a new node.js project using the below command

 

 

npm init -y

 

 

npm i a-csv

 

 

After that you need to make a new index.js file and copy paste the following code

 

 

index.js

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var CSV = require("a-csv");
var file = "users.csv";
var options = {
  delimiter: ",",
  charset: "win1250",
};
 
CSV.parse(file, options, function (err, row, next) {
  if (err) {
    return console.log(err);
  }
 
  if (row !== null) {
    console.log(row);
    return next();
  }
 
  console.log("finish");
});

 

 

As you can see we are importing the library at the top and then we are loading the input csv file which is users.csv file and then we are providing the delimiter which is comma and then we are using the parse() method to provide the input file and then we are providing the options object and then we are also having the callback function in which we will be reading the contents of the file and showing it inside the command line.

 

 

 

Recent Posts

  • Android Java Project to Capture Image From Camera & Save it in SharedPreferences & Display it in Grid Gallery
  • Android Java Project to Store,Read & Delete Data Using SharedPreferences Example
  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme