I have a node application that queries a MySQL database and writes results to a file.
The query result is a piece of text with translations to most world languages.
My issue is that most non ASCII chars don't display properly. For example
Wir möchten
Is written to file as:
Wir möchten
This is how I connect to the database:
const mysql = require("mysql");
const connection = mysql.createConnection({
host: "",
user: "",
password: "",
database: "",
charset: "utf8", // I have tried 'utf8'/'latin1'/'BIG5'
});
This is the function that writes query result to file:
query(sql, (err, data) => {
fs.writeFile("x.json", JSON.stringify(data), "utf8", function (err) {
if (err) throw err;
console.log("Saved!");
});
});