-1

I want to try to read my csv file and convert it so that I have the german umlauts back in. How can I convert this?

my code:

export const convertCSV = (req: Request, res: Response) => {
    const file = fs.readFileSync(path.resolve(__dirname, '..', 'files', 'csv.csv'), "utf-8");
    let csvData: any = [];
    papa.parse(file, {
        dynamicTyping: true,
        skipEmptyLines: true,
        step: function (result) {
            csvData.push(result.data)
        },
        complete: function (results, file) {
            //console.log('Complete', results.data, 'records.');
        }
    })
    res.status(200).send(csvData)
}

With this code I always get these characters � if I have an umlaut. How can I solve this problem?

redlightfilms
  • 193
  • 1
  • 4
  • 13

1 Answers1

0

What version of Node are you running? The suggested string to pass for UTF-8 encoding in Node.js is "utf8", without the dash, however "utf-8" has been a valid alias for at least 5 years now. It may not have been in older releases.