0

I'm trying read from a file (The file is in Bulgarian) and with utf 8 it returns nonsense characters so I tried cp1251 but it throws: ERR_INVALID_OPT_VALUE_ENCODING.

var str = fs.readFileSync("./bank1/"+client,'cp1251');
Joey Phillips
  • 1,543
  • 2
  • 14
  • 22
  • Node.js has not supported cp1251 natively in the past. Supported natively are: ascii, base64, binary, hex, ucs2/ucs-2/utf16le/utf-16le, utf8/utf-8, and latin1. So you'll have to add a conversion library to cast the cyrillic to one of the above. Sidenote: The name can be `windows-1251` or `win1251`, depending on the library, instead of `cp1251`. – Shilly May 07 '19 at 13:35

1 Answers1

0

You should add the encoding option as an object like so:

var str = fs.readFileSync("./bank1/"+client, { encoding: 'cp1251' });

Hope it helps.

Rafael Rocha
  • 508
  • 1
  • 3
  • 16
  • Nope, problem is in value 'cp1251'. By the sources of lib available options are `type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";` – D Mak Jul 26 '20 at 09:03