Couple of things I learned:
- RSS Feeds don't send information. If you want to subscribe to one, you need to make the requests on an interval and parse new information: Subscribe to an RSS Feed
- Any functionality that doesn't require handling incoming requests probably doesn't need to be used in your Express middleware, you can just start the RSS subscription interval immediately before/after starting your HTTP server:
var app = require('../app');var http = require('http');var port = normalizePort(process.env.PORT || '3000');app.set('port', port);/** * Create HTTP server. */var server = http.createServer(app);/** * Listen on provided port, on all network interfaces. */server.listen(port);server.on('error', onError);server.on('listening', onListening);/** * Start the subscriber */var feed = new RssFeed({your rss feed url}, 60000); // 60000 = 60 second refresh ratefeed.start();
Also including an incomplete snippet of my implementation:
const Parser = require('rss-parser')class RssSubscriber extends Parser { constructor (url, interval) { super() this.url = url this.interval = interval this.latestPublishTime = null } start () { // execute on an interval setInterval(async () => { try { console.log('Fetching feed...') const news = await this.parseFeed() await Promise.all(news.map(n => { return this.alert(n) })) } catch (err) { console.log('WARN: Error Encountered when fetching subscription items.') } }, this.interval) }