How to fix charset="UTF-8" in application nodejs inside socket.io

0

I have a chat app and am working with nodejs and socket.io . But I'm having trouble coding names. The following name: Guilherme Loução is coming as: Guilherme Louçço . I already saved the file in UTF-8 format and it did not work. Is there any module to fix this inside socket.io?

Code:

...
io.sockets.on('connection', ioJwt.authorize({
  secret: jwtSecret,
  timeout: 15000
})).on('authenticated', function(socket) {

  socket.on('join', function(data){

    console.log(data.name);
  });
  ...
});
...
    
asked by anonymous 07.06.2017 / 16:33

1 answer

1

Your page should be using iso-8859-1 / windows-1252 and the JSON response returns in utf-8, you can change the page (or add-on) to use:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

You also need to save the documents (if you have some, like .html or templates) as UTF-8 without BOM .

However if you want to use iso-8859-1 you can try to decode from utf-8, first install this via npm :

npm install utf8

Then call it like this:

var utf8 = require('utf8');

Then use:

console.log( utf8.decode(data.name) );
    
07.06.2017 / 18:56