Skip to content

Instantly share code, notes, and snippets.

@phi-jp
Last active December 27, 2018 04:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phi-jp/950a4a3ed9afc1b5fccc to your computer and use it in GitHub Desktop.
Save phi-jp/950a4a3ed9afc1b5fccc to your computer and use it in GitHub Desktop.
Feedparser Usage
/*
* feed.js
*/
var FeedParser = require('feedparser');
var request = require('request');
var feed = 'http://phiary.me/rss';
var req = request(feed);
var feedparser = new FeedParser({});
var items = [];
req.on('response', function (res) {
this.pipe(feedparser);
});
feedparser.on('meta', function(meta) {
console.log('==== %s ====', meta.title);
});
feedparser.on('readable', function() {
while(item = this.read()) {
// console.log(item);
items.push(item);
}
});
feedparser.on('end', function() {
// show titles
items.forEach(function(item) {
console.log('- [' + item.title + ']' + '(' + item.link + ')');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment