-2

I am develop in node.js I get file text-content using fs-module. This is .txt file

Привет мир
Hello world
Hello world
...

After I want to send this content to user to show using res.end(fileString)

But my browser can't decode russian symbols. Only english words are correct.

Alexander Knyazev
  • 2,692
  • 4
  • 15
  • 25

1 Answers1

0

First and foremost, be sure that the browser is set correctly to use UTF-8 encoding.

If the text still does not show correctly, you can try an alternate encoding for sending the data, depending on how you're doing this.

As an example, you can encode the Russian in base64 prior to sending it over to the browser, and decode it on the browser side.

On the NodeJS side, you can use Buffer to encode the utf8 string to base64. Reference this thread for examples and more details.

On the client/browser side, the atob() and btoa() functions are used rather than Buffer. Here is the documentation for these functions. Use atob() in order to decode the base64 to utf8, and the browser will be able to show this correctly.