Node RSS Feed

Wed Jan 22 2020

One of the beautiful things about Node is that it is really easy to do just about anything in a few lines of code. To put this in perspective, it took me longer to make this terrible blog post header than it did for me to implement an RSS feed in node. An RSS (rich site summary) feed enables people to subscribe to blogs and get notified when there is a new post. People also use RSS feeds to aggregate all the blogs they read in one place. Although RSS is on the decline, it is still widely used in the tech community.

Before looked for a package I added a route listening on “/rss” which sends a static object that will eventually store the RSS feed object.

routes.get('/rss', (request, result) =>
    result.set('Content-Type', 'text/xml');

The next step was to find a nifty node package that handles the generation of RSS XML. I’m using the package adequately named “RSS”.

npm install -s rss

Based on the documentation for the package, I initialized the RSS generator object.

// defines basic details about your blog
var feed = new RSS({
    title: 'jrtechs',
    description: 'Jeffery\'s blog which has everything from data-science to cooking',
    feed_url: '',
    site_url: '',
    image_url: '',
    docs: '',
    language: 'en',
    categories: ['other', 'hardware', 'open-source', 'programming', 'projects', 'web-development', 'data-science'],

var xmlFeed = feed.xml();

The final step was to add all the recent posts to the RSS feed.

const sql = require('../utils/sql');
    posts.forEach(post =>
            url: "" + post.category + "/" + post.url,
            date: post.published
    xmlFeed = feed.xml();

Although my implementation is probably very rudimentary, it is flexible and implementing it myself gave me a deeper appreciation for RSS. Looking through the package documentation, I discovered a multitude of details that RSS feeds could contain that I didn’t know about.