Sometimes latin alphabet (ä ö ü è ß) characters are returned as �

I want to return in response the orginal text.

But when I have the letter ä, I'm sometimes getting �� instead.

e.g. for Stäblistraße, The cloud returns St��blistraße. It's not always happened. But even one time is too much..

How can I verify it will never happened again?

I tried utf8.decode(value) But not working - Error: Invalid continuation byte.

Attached code snippet:

var sendResponse = function(res,response,type)
{
  res.writeHeader(200, {
    "Content-Type" : "text/plain"
  });
  res.write((JSON.stringify(response))+"\n");
  res.end();
}

You are outputting valid UTF-8 already in St��blistraße, since the ä is rendered as two bytes. However, your browser doesn't know it's UTF-8. Either send the header (probably using response.setHeader()):

Content-Type: text/html; charset=utf-8

or include a meta tag in your HTML:

  • In HTML5,

    <meta charset="utf-8">
    
  • In HTML4/XHTML,

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

(Assuming you're sending HTML to a browser; you are a bit vague on the details).

To output the value try use the coressponding entities

ä =  &auml;
ö =   &ouml;
ü =   &uuml;
ß =   &szlig;
eg Stäblistraße,  will be St&auml;blistra&szlig;e, 

var myText = new Buffer('Stäblistraß', 'utf8')
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
res.write(encodeURIComponent.myText.toString('utf8'));

On the browser end, use decodeURIComponent() to convert string back. Works every time.