1

I have this error when I try to parse kepler_data.csv using csv-parse using promises following Adam and Andre Negoi NodeJS course. Here is the code:

function loadPlanetsData() {
    return new Promise((resolve, reject) => {
        fs.createReadStream(
            path.join(__dirname, "..", "..", "data", "kepler_data.csv")
        )
            .pipe(
                parse({
                    comment: "#",
                    columns: true,
                })
            )
            .on("data", (data) => {
                if (isHabitalePlanet(data)) {
                    habitablePlanets.push(data);
                }
            })
            .on("error", (err) => {
                console.log(err);
                reject(err);
            })
            .on("end", () => {
                console.log(
                    `${habitablePlanets.length} habitable planets found!`
                );
                console.log("Done reading!!");
                resolve();
            });
    });
}

I tried to indicate relax-quotes but it doesn't work. How can i fix this?

trincot
  • 317,000
  • 35
  • 244
  • 286
Sycan
  • 37
  • 8

1 Answers1

1
parse({
  comment: "#",
  columns: true,
  relax_quotes: true,
  escape: "\\",
  quote: "'",
  delimiter: ",",
  ltrim: true,
  rtrim: true,
  record_delimiter: "\n",
  skip_empty_lines: true,
  relax_column_count: true
})
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Amit
  • 26
  • 1
  • Thanks. This has helped alot. However this is what works for me: ` parse({ comment: "#", columns: true, relax_quotes: true, escape: '", quote: ', delimiter: ",", record_delimiter: "\n", skip_empty_lines: true, relax_column_count: true, }) ` – Sycan Sep 19 '22 at 11:21
  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Sep 22 '22 at 20:39