I need to read a file which is encoded with ISO-8859-1 (also called latin1), something like this:
var file_contents = fs.readFileSync("test_data.html", "latin1");
However, Node complains about “latin1” or “ISO-8859-1” not being a valid encoding (“Error: Unknown encoding”).
What encodings does readFileSync accept?
The list of encodings that node supports natively is rather short:
If you are using an older version than 6.4.0, or don’t want to deal with non-Unicode encodings, you can recode the string:
Use iconv-lite to recode files:
Alternatively, use iconv: