The [list of encodings](https://github.com/nodejs/node/blob/master/lib/buffer.js) that node supports natively is rather short:
* ascii
* base64
* hex
* ucs2/ucs-2/utf16le/utf-16le
* utf8/utf-8
* binary/latin1 (ISO8859-1, latin1 only in node 6.4.0+)
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 <a href="https://github.com/ashtuchkin/iconv-lite">iconv-lite</a> to recode files:
var iconvlite = require('iconv-lite');
var fs = require('fs');
function readFileSync_encoding(filename, encoding) {
var content = fs.readFileSync(filename);
return iconvlite.decode(content, encoding);
}
Alternatively, use <a href="https://github.com/bnoordhuis/node-iconv">iconv</a>:
var Iconv = require('iconv').Iconv;
var fs = require('fs');
function readFileSync_encoding(filename, encoding) {
var content = fs.readFileSync(filename);
var iconv = new Iconv(encoding, 'UTF-8');
var buffer = iconv.convert(content);
return buffer.toString('utf8');
}