Thursday, October 18, 2012 9:05 PM

Get on your feed: Using node-rss with express and mongojs

Author: matthias - Last modified: Friday, June 21, 2013 2:41 PM

en node-rss  rss  nodejs  express  mongojs

This post shows a code snippet as an example for setting up a rss feed by integrating node-rss with express using a mongodb/mongojs result array.

Note: I just were going to add this stuff as a Gist on Github which at the time of writing this experiences major disruptions. Well, I'll do better publishing it directly in my blog by now.

Situation

For my tiny blog (engine) based on node, express/connect and mongojs I needed a simple rss feed solution. I discovered and decided to go with the nice working npm module node-rss instead of writing xml myself.

What this code example does

Basically I create an get event on route /feed/rss, generate a node-rss object initialized with base values and add item elements to it while looping over a mongojs collection result array (holding my post items to be reflected). Finally I send a response with an appropriate content type header. My example is directly bound to an express get event callback for a simple static request path, but you may of course move it to route exports or whatever.

Notes

No big deal, but you might find this portion of code useful as a starting point when seeking for rss solutions.

Comment / Share »