• Stars
    star
    995
  • Rank 46,046 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RSS feed generator for Node.

rss Build Status rss

RSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS.

Usage

Create a new feed

var RSS = require('rss');

var feed = new RSS(feedOptions);
feedOptions
  • title string Title of your site or feed
  • description optional string A short description of the feed.
  • generator optional string Feed generator.
  • feed_url url string Url to the rss feed.
  • site_url url string Url to the site that the feed is for.
  • image_url optional url string Small image for feed readers to use.
  • docs optional url string Url to documentation on this feed.
  • managingEditor optional string Who manages content in this feed.
  • webMaster optional string Who manages feed availability and technical support.
  • copyright optional string Copyright information for this feed.
  • language optional string The language of the content of this feed.
  • categories optional array of strings One or more categories this feed belongs to.
  • pubDate optional Date object or date string The publication date for content in the feed
  • ttl optional integer Number of minutes feed can be cached before refreshing from source.
  • hub optional PubSubHubbub hub url Where is the PubSubHub hub located.
  • custom_namespaces optional object Put additional namespaces in element (without 'xmlns:' prefix)
  • custom_elements optional array Put additional elements in the feed (node-xml syntax)

Add items to a feed

An item can be used for a blog entry, project update, log entry, etc. Your RSS feed can have any number of items. Most feeds use 20 or fewer items.

feed.item(itemOptions);
itemOptions
  • title string Title of this particular item.
  • description string Content for the item. Can contain html but link and image urls must be absolute path including hostname.
  • url url string Url to the item. This could be a blog entry.
  • guid unique string A unique string feed readers use to know if an item is new or has already been seen. If you use a guid never change it. If you don't provide a guid then your item urls must be unique.
  • categories optional array of strings If provided, each array item will be added as a category element
  • author optional string If included it is the name of the item's creator. If not provided the item author will be the same as the feed author. This is typical except on multi-author blogs.
  • date Date object or date string The date and time of when the item was created. Feed readers use this to determine the sort order. Some readers will also use it to determine if the content should be presented as unread.
  • lat optional number The latitude coordinate of the item.
  • long optional number The longitude coordinate of the item.
  • custom_elements optional array Put additional elements in the item (node-xml syntax)
  • enclosure optional object An enclosure object
    /* enclosure takes url or file key for the enclosure object
    
      url:  _required_ url to file object (or file)
      file: _required_ path to binary file (or url)
      size: _optional_ size of the file
      type: _optional_ if not provided the mimetype will be guessed
                       based on the extension of the file or url,
                       passing type to the enclosure will override the guessed type
    */
    
    {
      'url'  : 'http://www.example.com/path/to/image',
      'size' : 1668, //
      'type' : 'image/jpeg'
    }
Feed XML
var xml = feed.xml({indent: true});

This returns the XML as a string.

indent optional boolean or string What to use as a tab. Defaults to no tabs (compressed). For example you can use '\t' for tab character, or ' ' for two-space tabs. If you set it to true it will use four spaces.

Example Usage

var RSS = require('rss');

/* lets create an rss feed */
var feed = new RSS({
    title: 'title',
    description: 'description',
    feed_url: 'http://example.com/rss.xml',
    site_url: 'http://example.com',
    image_url: 'http://example.com/icon.png',
    docs: 'http://example.com/rss/docs.html',
    managingEditor: 'Dylan Greene',
    webMaster: 'Dylan Greene',
    copyright: '2013 Dylan Greene',
    language: 'en',
    categories: ['Category 1','Category 2','Category 3'],
    pubDate: 'May 20, 2012 04:00:00 GMT',
    ttl: '60',
    custom_namespaces: {
      'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'
    },
    custom_elements: [
      {'itunes:subtitle': 'A show about everything'},
      {'itunes:author': 'John Doe'},
      {'itunes:summary': 'All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our podcast in the Podcasts app or in the iTunes Store'},
      {'itunes:owner': [
        {'itunes:name': 'John Doe'},
        {'itunes:email': '[email protected]'}
      ]},
      {'itunes:image': {
        _attr: {
          href: 'http://example.com/podcasts/everything/AllAboutEverything.jpg'
        }
      }},
      {'itunes:category': [
        {_attr: {
          text: 'Technology'
        }},
        {'itunes:category': {
          _attr: {
            text: 'Gadgets'
          }
        }}
      ]}
    ]
});

/* loop over data and add to feed */
feed.item({
    title:  'item title',
    description: 'use this for the content. It can include html.',
    url: 'http://example.com/article4?this&that', // link to the item
    guid: '1123', // optional - defaults to url
    categories: ['Category 1','Category 2','Category 3','Category 4'], // optional - array of item categories
    author: 'Guest Author', // optional - defaults to feed author property
    date: 'May 27, 2012', // any format that js Date can parse.
    lat: 33.417974, //optional latitude field for GeoRSS
    long: -111.933231, //optional longitude field for GeoRSS
    enclosure: {url:'...', file:'path-to-file'}, // optional enclosure
    custom_elements: [
      {'itunes:author': 'John Doe'},
      {'itunes:subtitle': 'A short primer on table spices'},
      {'itunes:image': {
        _attr: {
          href: 'http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg'
        }
      }},
      {'itunes:duration': '7:04'}
    ]
});

// cache the xml to send to clients
var xml = feed.xml();

Notes

  • You do not need to escape anything. This module will escape characters when necessary.
  • This module is very fast but you might as well cache the output of xml() and serve it until something changes.

Inspiration

I started this module years ago (April 2011) because there weren't any Node modules for creating RSS. Nearly 50 modules use RSS, as well as many web sites and the popular Ghost publishing platform.

Contributing

Contributions to the project are welcome. Feel free to fork and improve. I do my best accept pull requests in a timely manor, especially when tests and updated docs are included.

About the Author

Hi! Thanks for checking out this project! My name is Dylan Greene. When not overwhelmed with my two young kids I enjoy contributing to the open source community. I'm also a tech lead at Opower. @dylang @dylang

Here's some of my other Node projects:

Name Description npm Downloads
npm‑check Check for outdated, incorrect, and unused dependencies. npm-check
grunt‑notify Automatic desktop notifications for Grunt errors and warnings. Supports OS X, Windows, Linux. grunt-notify
shortid Amazingly short non-sequential url-friendly unique id generator. shortid
grunt‑prompt Interactive prompt for your Grunt config using console checkboxes, text input with filtering, password fields. grunt-prompt
xml Fast and simple xml generator. Supports attributes, CDATA, etc. Includes tests and examples. xml
changelog Command line tool (and Node module) that generates a changelog in color output, markdown, or json for modules in npmjs.org's registry as well as any public github.com repo. changelog
space‑hogs Discover surprisingly large directories from the command line. space-hogs
observatory Beautiful UI for showing tasks running on the command line. observatory
captionbot Get captions for image using Microsoft's CaptionBot 🤖 captionbot
grunt‑attention Display attention-grabbing messages in the terminal grunt-attention
what‑dog Get the breed of a dog from an image using Microsoft's what-dog. what-dog
anthology Module information and stats for any @npmjs user anthology
random‑puppy Get a random imgur image url, by default a puppy. random-puppy
grunt‑cat Echo a file to the terminal. Works with text, figlets, ascii art, and full-color ansi. grunt-cat

This list was generated using anthology.

License

Copyright (c) 2017 Dylan Greene, contributors.

Released under the MIT license.

Screenshots are CC BY-SA (Attribution-ShareAlike).


Generated using grunt-readme with grunt-templates-dylang on Wednesday, January 11, 2017. _To make changes to this document look in /templates/readme/

More Repositories

1

npm-check

Check for outdated, incorrect, and unused dependencies.
JavaScript
6,553
star
2

shortid

Short id generator. Url-friendly. Non-predictable. Cluster-compatible.
JavaScript
5,736
star
3

grunt-notify

Automatic Notifications when Grunt tasks fail.
JavaScript
921
star
4

grunt-prompt

Add interactive UI to your Gruntfile such as lists, checkboxes, text input with filtering, and password fields, all on the command line.
JavaScript
368
star
5

observatory

Beautiful UI for showing tasks running on the command line.
JavaScript
276
star
6

node-xml

Fast and simple Javascript-based XML generator/builder for Node projects.
JavaScript
274
star
7

changelog

Finally see what's changed when you do npm update. Changelog generates a changelog for npm modules and github repos.
JavaScript
239
star
8

space-hogs

Discover surprisingly large directories from the command line.
JavaScript
161
star
9

opowerjobs

Node.js site using Express and Connect.
JavaScript
61
star
10

logging

Lightweight informative modern console logging.
JavaScript
54
star
11

anthology

List of modules for any npm user, plus number of downloads and github stars.
JavaScript
46
star
12

captionbot

Get captions for image using Microsoft's CaptionBot
JavaScript
41
star
13

grunt-attention

Display attention-grabbing messages in the terminal.
JavaScript
26
star
14

jira-improved

Improves the Jira Agile board by showing the Epic name in the cards and hiding the Done column if you use a quick filter to hide tickets in that column.
JavaScript
24
star
15

node-atom

DEPRECATED - NOT MAINTAINED
JavaScript
20
star
16

what-dog

Get the breed of a dog from an image using Microsoft's what-dog
JavaScript
15
star
17

grunt-cat

Echo a file to the terminal. Works with text, figlets, ascii art, and full-color ansi.
JavaScript
14
star
18

random-puppy

Get a random puppy image url.
JavaScript
13
star
19

jobvite

DEPRECATED ----- Jobvite API for Node
JavaScript
12
star
20

source-map-diff

Compare source maps with cli and web output
TypeScript
7
star
21

flowdock-refined

DEPRECATED - Flowdock desktop app custom UI
CSS
5
star
22

...

really, this is a valid project name?
2
star
23

dotfiles

Vim Script
2
star
24

lean

Simple in-memory data store to lean on. Helpful when you don't need a couch.
JavaScript
2
star
25

jquery-tooltips

Easy to use image-free HTML5 tooltips for jQuery 1.5.2+.
JavaScript
2
star
26

grunt-templates-dylang

Templates for grunt-readme that dylang will be using across multiple projects.
JavaScript
1
star
27

dotconfig

My custom terminal colors, bash-it prompt, intellij and webstorm settings, etc
Shell
1
star
28

dylang.github.com

Everything you need to know about me.
1
star