danmactough / node-feedparser

Robust RSS, Atom, and RDF feed parsing in Node.js
Other
1.97k stars 190 forks source link

Cannot use more than one instance of FeedParser #201

Closed briantkatch closed 7 years ago

briantkatch commented 7 years ago

I want to use multiple instances of FeedParser to monitor multiple feeds, however, I can only get FeedParser to monitor and trigger events on the latest instance of FeedParser that I have created. For example:

var FeedSub = require("feedsub");

var feeds = [ "feedA", "feedB", "feedC" ];

for (var i = 0; i < feeds.length; i++) {
    // Lorem RSS is a testing service that will publish a new an item once a
    // minute. That query parameter doesn't actually change anything, but it
    // gives each feed a unique URL.
    var subscription = new FeedSub("http://lorem-rss.herokuapp.com/feed?" + feeds[i]);
    subscription.readInterval(60000);

    console.log("Subscribed to feed for " + feeds[i]);

    subscription.on("item", function(item) {
        console.log("New feed item for " + feeds[i] + ": " + JSON.stringify(item));
    });

    subscription.on("error", function(error) { console.log("Error with feed for " + thisRegion, error); });
}

I see this in my terminal when I run that script:

Subscribed to feed for feedA
Subscribed to feed for feedB
Subscribed to feed for feedC
New feed item for feedC: {"title":"Lorem ipsum 2017-02-24T20:26:00+00:00","description":"Voluptate ullamco ex velit fugiat pariatur et laborum labore.","link":"http://example.com/test/1487967960","guid":{"ispermalink":"true","text":"http://example.com/test/1487967960"},"dc:creator":"John Smith","pubdate":"Fri, 24 Feb 2017 20:26:00 GMT"}
New feed item for feedC: {"title":"Lorem ipsum 2017-02-24T20:27:00+00:00","description":"Laborum cillum occaecat nostrud ad dolor pariatur mollit quis consequat aute.","link":"http://example.com/test/1487968020","guid":{"ispermalink":"true","text":"http://example.com/test/1487968020"},"dc:creator":"John Smith","pubdate":"Fri, 24 Feb 2017 20:27:00 GMT"}
[...]
New feed item for feedC: {"title":"Lorem ipsum 2017-02-24T20:33:00+00:00","description":"Elit proident eu enim reprehenderit magna magna adipisicing reprehenderit consequat ea amet eu.","link":"http://example.com/test/1487968380","guid":{"ispermalink":"true","text":"http://example.com/test/1487968380"},"dc:creator":"John Smith","pubdate":"Fri, 24 Feb 2017 20:33:00 GMT"}
New feed item for feedC: {"title":"Lorem ipsum 2017-02-24T20:34:00+00:00","description":"Officia adipisicing mollit eu deserunt nulla anim do.","link":"http://example.com/test/1487968440","guid":{"ispermalink":"true","text":"http://example.com/test/1487968440"},"dc:creator":"John Smith","pubdate":"Fri, 24 Feb 2017 20:34:00 GMT"}

I see all the historical and new items coming in for feedC, but I don't see anything for feedA or feedB. I have also tried completely different feeds, with the same results.

briantkatch commented 7 years ago

Filed on wrong project; apologies.