You need to do the conversion yourself. The following code example uses node-iconv.
var Iconv = require('iconv').Iconv; var request = require('request'); request({ uri: 'http://www.jalan.net/', encoding: null, }, function (error, response, body) { if (!error && response.statusCode == 200) { body = new Iconv('shift_jis', 'utf-8').convert(body).toString(); console.log(body);
- The
encoding: null parameter requests request not to convert the Buffer (array of bytes) to String . - We pass this buffer to
Iconv for conversion to another UTF-8 encoding buffer. - Now this
Buffer is good for converting to string.
(BTW, http://www.alc.co.jp switched to UTF-8, so I replaced another site.)
source share