Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /usr/bin/env node
var feedparser = require( 'feedparser' );
var request = require( 'request' );
var feedTest = function (url){
var object = {};
object.articles =[];
request( url, {timeout: 20000}, function(error, resp, body){
if (error){
console.log(url + " : " + error);
}
else {
console.log(resp.statusCode);
console.log(body);
}
})
.pipe(new feedparser())
.on('error', function(err){
console.log(url + " : " + err);
object = null;
})
.on ( 'meta', function ( meta ){
object["meta"] = meta;
})
.on('readable', function(){
var stream = this, item;
while (item = stream.read()) {
object["articles"].push ( item );
}
})
.on( 'end', function() {
console.log ( JSON.stringify( object && object.meta.title ) );
});
}
var url = "http://dave.smallpict.com/rss.xml";
feedTest ( url );
/** output
* http://dave.smallpict.com/rss.xml : Error: Not a feed
* null
* */
// var url2 = "http://scripting.com/rss.xml";
// feedTest ( url2 );
/** output
* "Dave Winer"
* */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment