A simple node.js RSS feed builder
None of the other node.js RSS modules that I could find supported the flexibility that I wanted or were too slow. Additionally, many of them seemed overly complex when all we're doing here is building a RSS feed. Not rocket science.
Install
npm install node-rss
Dependencies
Update (6/18/2015): This step should no longer be necessary.
node-rss uses the libxmljs library to construct the actual feed.
Unfortunately, some of the features of the library that are needed are only available in the current master branch. You will need to download the libxmljs source, compile, and install it yourself. Fortunately, this is fairly straight forward. https://github.com/polotek/libxmljs/
You will also need to have the libxml2 AND libxml2-dev packages installed on your system.
Usage
var rss = require('node-rss');
var feed = rss.createNewFeed('Blog Most Recent', 'http://someurl.com/',
'Most recent blog entries from blog',
'EJ Bensing',
'http://someurl.com/rss/MostRecent.xml',
{'CustomTag' : 'This is a custom tag under the channel tag!' });
var blogs = [
{title: 'blog post 1', url : 'http://someurl.com/blog1', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 2', url : 'http://someurl.com/blog2', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 3', url : 'http://someurl.com/blog3', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 4', url : 'http://someurl.com/blog4', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 5', url : 'http://someurl.com/blog5', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 6', url : 'http://someurl.com/blog6', pubDate : new Date(), description: 'this is a description' },
];
blogs.forEach(function (blog) {
feed.addNewItem(blog.title, blog.url, blog.pubDate, blog.description, {});
});
var xmlString = rss.getFeedXML(feed);
Other
The "feed" object has a defaults property. Inside this is a dictionary of default values.
cdata : a list of tag names whose content should be "escaped" in CDATA tags
tests
In the process of building these...
TODO
- add tests
- add support for attributes on custom tags
- add some express.js middleware
- ?? give me suggestions
Change log
Version 1.0.5
- Updated libxml version to 0.15.x to support node.js 4.x (Thanks @dhendo)
Version 1.0.4
- Updated libxml version to 0.14.x to support compilation on OSX (Thanks @jmathews)
Version 1.0.3
- update libxml version to 0.13.0