订阅 RSS/Atom/JSON 来源,并对新条目发出通知。
FeedSub subscribes to a remote RSS/Atom/JSON feed and notifies you of any new items it reads.
It works by checking the feed every once in a while, comparing the date of the document via a conditional GET if supported. Otherwise it looks for a date tag in the feed. If it's the same as the last date, it stops downloading it and parsing the xml/json. If it's an updated document, then it looks through it top to bottom taking note of all the new items. Once it finds something it has already read, it stops downloading and parsing the document.
const FeedSub = require('feedsub');
let reader = new FeedSub('http://rss.cnn.com/rss/cnn_latest.rss', {
interval: 10 // Check feed every 10 minutes.
});
reader.on('item', (item) => {
console.log('Got item!');
console.dir(item);
});
reader.start();Creates a new instance of FeedSub. options defaults to.
…Reads the feed. Calls callback with possible error or new items discovered if provided. Causes reader to emit new item events.
Starts checking the feed for any new items every options.interval minutes. If readOnStart is true, it checks right away.
Options that were passed to the constructor along with any defaults are kept here.
Stops the reader from automatically reading the feed.
Object - Item.Emitted whenever there is a new item.
Array. - List of items.Emits all new items from one request in one array.
ErrorEmitted when there is an error downloading or parsing the feed. Not emitted if callback is given for read or readInterval.
npm install feedsubTests are written with mocha
npm test暂无开放 Issues,或尚未同步最近议题。