Read text file using node js

I don’t know how this is possible new to programming. I want to print the values which are present in abc.txt, but don’t know how to do it using Node.js:

abc.txt
[
mainfodler/subfolder/pqr.pdf, PQR
mainfodler/subfolder2/xyz.doc, XYZ
mainfodler/subfolder/image1.jpg, Image
mainfodler/subfolder2/pqr.pdf, PQR
]

Expected output:

Array1:
[
mainfodler/subfolder/pqr.pdf
mainfodler/subfolder2/xyz.doc
mainfodler/subfolder/image1.jpg
mainfodler/subfolder2/pqr.pdf
]

Array2
[
PQR
XYZ
Image
PQR
]

Answer

You can use readline from node.js. Here is the code you can use:

const readline = require('readline');
const fs = require('fs');

async function readFile(filePath) {   
const myInterface = readline.createInterface({ input: fs.createReadStream(filePath)});    
  const arrayLink = [],     
        arrayName = []; 

  for await (const line of myInterface) {
    let temp = line.split(",");
    arrayLink.push(temp[0]);     
    arrayName.push(temp[1]);     
  }
  console.log(arrayLink, arrayName);
}
readFile(filePath)

This Updated code will run the way you are expecting. Check this one.