node.jscharacter-encodingnode-fetch

fetch response replaces Hebrew with question marks in black diamonds


 const fetch = require("node-fetch")

 fetch("https://www.example.com")
 .then(res => res.text())
 .then(data => console.log(data))

The output is HTML string, but Hebrew words replaced with ���� ����

How to set proper encoding to show Hebrew text properly? The final goal is to check whether multiple websites contain certain Hebrew keyword.


Solution

  • By default (res.text()) assumes utf8 has been used, but, as pointed out by this issue, it's not always the case. That might be your case, in which case you might want to try replacing res.text() by res.textConverted() so as to perform encoding sniffing before converting to a string.