Q:

Is it possible to load ansi encoded string using nodejs

I have large quantity of html files (around 2k).
These html`s are result of conversion from word documents.
The files have some hebrew text inside html tags. I can see the text perfectly using vscode or notepad++ editors.  
My goal is to loop through the folder and insert the contents of files into some DB. 
Since i have a little knowledge of nodejs - i decided to build the "looping" using node. 
Here is where i finished so far:  
fs.readdir('./myFolder', function (err, files) {
    total = files.length;

    let fileArr = []
    for(var x=0, l = files.length; x<l; x++) {
      const content = fs.readFileSync(`./myFolder/${files[x]}`, 'utf8');    

      let title = content.match(/<title>(.*?)<\/title>/g).pop()

      fileArr.push({id:files[x] , title})
    }
});

The problem is: although the text displayed correctly inside editors -when debugging - i can see that "title" variable get strings which consists of question marks
 
I guess the problem is with file encoding, am i right here?
If so - is there way to decode the string?
P.S. my OS is windows10
Thanks

A:

There are a couple of possibilities here, it may be possible that your input files are in a multibyte encoding (such as utf8 utf16 etc) and your debugger is simply not showing the correct characters due to font restrictions. 
I would try writing the title variable to some test file like so: 
fs.writeFileSync(`title-test-${x}.txt`, title, "utf8");

And see if the title looks correct in your text editor.
It may also be possible that the files are encoded in an extended ascii encoding such as Windows 1255 or ISO 8859-8. If this is the case, fs.readFileSync will not work correctly since it does not support these encodings (see node.js encoding list)
If the files are encoded using a single-byte extended ascii encoding, it should be possible to convert to a more portable encoding (such as utf8). 
I'd recommend the iconv-lite module for this purpose, you can do a lot with it!
For example, to convert from a Windows 1255 file to utf8 you could try: 
    const iconv = require("iconv-lite");
    const fs = require("fs");

    // Convert from an encoded buffer to JavaScript string.
    const fileData = iconv.decode(fs.readFileSync("./hebrew-win1255.txt"),  "win1255");

    // Convert from JavaScript string to a buffer.
    const outputBuffer = iconv.encode(fileData, "utf8");

    // Write output file..
    fs.writeFileSync("./hebrew-utf8-output.txt", outputBuffer);

