I'm trying to pull in data from a URL (xyz.com/feed.xml). I'd like to save the XML data from that URL to a new file on my server. I also need to parse or traverse the data coming in then save to a file. Here is my thought process.
Using the following modules: fs(writing), http(requesting the data)
var fs = require('fs');
var http = require('http');
var feedURL = "xyz.com/feed";
http.get(feedURL, function(res) {
if( itemIsReadable ){
console.log("Got response: " + res);
}
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Is there also a way to check if xml data exists? For example, I only want to write/cache the data if it does not exist since I am using this as a data caching script. The app the data comes from frequently goes down and throws PHP errors so I'd like to check for that.
Thanks for the help. New to nodejs.