I'm working on a project, and my mother tongue is spanish and inside my database I'm using characters such as "ñ" and "é". When I'm using the psql shell those characters properly show on the terminal, but when I make a query using node-postgress those characters doesn't show up, instead I get ¤ or ¢.
In my database I have both client_encoding and server_encoding to UTF8, and I even checked with node-postgress, using a query, to see if they also were set to UTF8 and they didn't change for some other reason.
My database connection it's set up like this
const { Pool } = require("pg");
const db = new Pool({
user: user,
password: password,
host: localhost,
port: 5432,
database: my_database,
});
module.exports = db;
And the code for my query is like this:
const router = require("express").Router(),
db = require("../database/db");
//GET A PLACE ROUTE
router.get("/", async (req, res) => {
try {
const place = await db.query("SELECT * FROM places");
console.log(place.rows[0].name);
res.status(200).json({
status: "success",
data: {
place_name: place.rows[0].name,
},
});
} catch (error) {
console.error(error.message);
res.status(500).send("Error del servidor");
}
});
And now, if the name of the place is for example "Salón de peñas", how it will show up both in the console.log and my json response will be like "Sal¢n de pe¤as".
At first, I thought that the problem was because I didn't correctly set up my json response charset, but then I sent these characters as a response, and they show up correctly. The problem is when these characters come from my database. I checked the database encoding (both the client and the server) and they're set to UTF8, and like I said before, these characters display correctly when I'm using the psql shell.
I'm basically having the exact same problem as this question that didn't get an answer