Quantcast
Channel: RSS subscription implementation on express server - Stack Overflow
Viewing all articles
Browse latest Browse all 2

RSS subscription implementation on express server

$
0
0

I'm setting up a node.js server that subscribes to an RSS feed. When a new item is published to the feed, I want the server to parse that information and pass it to an API which will alert end users. Can I use feedparser as my subscriber?

I understand that this library creates an EventEmitter that fires actions. Is it possible to export this function and make it run in parallel with my Express application?

Taken from the parser examples:

const FeedParser = require('feedparser')const request = require('request')const subscriber = async () => {  const req = request('https://www.reddit.com/.rss')  const feedparser = new FeedParser()  req.on('error', (error) => {    console.log(error)  })  req.on('response', (r) => {    const stream = this    if (r.statusCode !== 200) {      this.emit('error', new Error('bad status code'))    } else {      stream.pipe(feedparser)    }  })  feedparser.on('readable', () => {    // This is where the action is!    const stream = this    var item = ''    while (item = stream.read()) {      console.log(item)    }  })  return feedparser}module.exports = {   subscriber }

When I call this function, I am expecting the console to log new items but I am not getting any items. The reason why is unclear.

Bonus Question: Can I validate the subscription is working without having to wait for new items to be published? Is there an RSS tool or website that can simulate the behavior?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images