'How to read multiple csv files in for loop using javascript

I am reading a csv file in javascript using the code:

import csv
  
file = open(r'C:\Users\hu170f\Documents\TEST1\MAAP-S12_LH_UP_PASS-LN1-V1.csv')
csvreader = csv.reader(file)

Now I have multiple files in the same directory and I need to read all the files present in the directory sequentially in a for loop. How to proceed with this.



Solution 1:[1]

First of all, install and require all the dependencies. Example:

var fs = require('fs');
const path = require('path');
const mysqlConnection = require('./connection');
const fastcsv = require('fast-csv');

Loop through each CSV file argument and run the formatFile function on each

for (let i = 0; i < filePaths.length; i++) {
   formatFile(filePaths, i);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduard