Home > nodeJS, XML > Content Syndication with Node.js

Content Syndication with Node.js

ESA_RSS_node_full_image

Source : https://github.com/supun/contentSynd

Web syndication is a must for any Website wishing to share some entries easily to other systems. Better known under their format name like RSS) or Atom), they can be quite time consuming to generate without a module handling all their formating. Thanks to the power of Node’s package manager NPM, you can generate yours in no time.

Installing the feed wrapper

Before we start, head to your project folder and install the latest version of the module feed:

$ npm install feed

Building the feed

First, we need to initialize a new Feed object. When you initialize the object, you must provide general information related to your Web syndication feed.

var feed = new Feed({
 title: 'My Feed Title',
 description: 'This is my personnal feed!',
 link: 'http://example.com/',
 image: 'http://example.com/logo.png',
 copyright: 'Copyright © 2013 John Doe. All rights reserved',

author: {
 name: 'John Doe',
 email: 'john.doe@example.com',
 link: 'https://example.com/john-doe'
 }
 });

Second, you might want to identify your feed thematic. Both RSS) and Atom) formats offer the possibility to identify one or multiple categories. Again, this is super simple to add:

feed.category('Node.js');
feed.category('JavaScript');

This is the implicit way of calling the render request. By default, it will render a RSS) feed. You an also use the explicit way, allowing you to select between RSS) or Atom):

res.set('Content-Type', 'text/xml');
res.send(feed.render('rss-2.0'));

Here is the result.

<rss version="2.0">

<channel>
<title>My Feed Title</title>
<description>This is my personnal feed!</description>
<link>http://example.com/</link>
<author>john.doe@example.com (John Doe)</author>
<lastBuildDate>Tue, 31 Dec 2013 08:37:55 GMT</lastBuildDate>
<image>http://example.com/logo.png</image>
<copyright>Copyright © 2013 John Doe. All rights reserved</copyright><generator>Feed for Node.js</generator>
</channel>
</rss>

Advertisements
Categories: nodeJS, XML
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: