I have the following code snippet I am currently employing attempting to get Yahoo weather XML files:
// This script requires request libraries.
// npm install request
var fs = require('fs');
var woeid_array = fs.readFileSync('woeid.txt').toString().split("\n");
var grabWeatherFiles = function (array) {
//var http = require('http');
//var fs = require('fs');
array.forEach(
function(element) {
var http = require('http');
var file_path = 'xml/' + element + '.xml';
console.log(file_path);
var file = fs.createWriteStream(file_path);
var request = http.get('http://weather.yahooapis.com/forecastrss?w=' + element, function(response) {
response.pipe(file);
});
});
};
grabWeatherFiles( woeid_array );
This code snippet is successful at downloading the XML files. However, if I attempt to read the files and get the XML data inside a string so I can parse it, the files are 0'd out. Is node.js not writing this correctly? This happened both on my Mac and on c9.io. Any tips would be lovely. I am quite stuck in this part.