I have a function called fetchXML that is suppose to write an XML file to my root directory called feed.xml, and then I want to console.log the data inside feed.xml. I use fs.readFile AND I specify the encoding with 'utf-8' as shown in this question: Why does Node.js' fs.readFile() return a buffer instead of string?
But still the result of my console.log is a buffer. I checked inside feed.xml and it does indeed contain xml.
var out = fs.createWriteStream('./feed.xml'); var fetchXML = function() { var feedURL = 'http://www2.jobs2careers.com/feed.php?id=1237-2595&c=1&pass=HeahE0W1ecAkkF0l'; var stream = request(feedURL).pipe(zlib.createGunzip()).pipe(out); stream.on('finish', function() { fs.readFile('./feed.xml', 'utf-8', function(err, data) { console.log(data); }); }); } fetchXML();