Reputation: 22651
I just want store in Mongo (so in UTF8) the content of a RSS feed. But I cannot even download content properly encoded :
var request = require('request');
var iconv = require('iconv');
var feedTest = function(url) {
request(url, {timeout: 20000}, function(error, resp, body) {
if (error) {
console.log(url + " : " + error);
}
else
{
var ic = new iconv.Iconv('iso-8859-1', 'utf-8');
var buf = ic.convert(body);
var buffer = buf.toString('utf-8');
console.log(resp.statusCode);
console.log(buffer);
}
});
};
feedTest("http://feeds.feedburner.com/spin-off-actu");
The accent are not in clear. No problem in PHP with iconv, but with this NodeJS code what is wrong?
Upvotes: 3
Views: 4693
Reputation: 161447
The request module is already decoding body
into a utf8
string. If you tell it not to decode the response first, your code works great.
{timeout: 20000, encoding: null}
Upvotes: 7