RSS, Atom, and JSON feed generator for Node.js with strongly-typed TypeScript API
npx @tessl/cli install tessl/npm-feed@5.1.0Feed is a RSS, Atom, and JSON feed generator for Node.js that makes content syndication simple and intuitive. It provides a strongly-typed TypeScript API with chainable methods for configuring feeds, adding items, categories, and contributors, while automatically handling the complexities of different feed formats and XML/JSON serialization.
npm install feedimport { Feed } from "feed";
import type { Author, Category, Enclosure, Extension, FeedOptions, Item } from "feed";For CommonJS:
const { Feed } = require("feed");import { Feed } from "feed";
const feed = new Feed({
id: "http://example.com/",
title: "Feed Title",
description: "This is my personal feed!",
link: "http://example.com/",
language: "en",
image: "http://example.com/image.png",
favicon: "http://example.com/favicon.ico",
copyright: "All rights reserved 2013, John Doe",
updated: new Date(2013, 6, 14),
generator: "awesome",
feedLinks: {
json: "https://example.com/json",
atom: "https://example.com/atom"
},
author: {
name: "John Doe",
email: "johndoe@example.com",
link: "https://example.com/johndoe"
}
});
// Add items to the feed
feed.addItem({
title: "Hello World",
id: "http://example.com/hello-world",
link: "http://example.com/hello-world",
description: "This is an article about Hello World.",
content: "Content of my article",
author: [
{
name: "Jane Doe",
email: "janedoe@example.com",
link: "https://example.com/janedoe"
}
],
date: new Date(2013, 6, 14),
image: "http://example.com/hello-world.png"
});
// Generate different feed formats
console.log(feed.rss2()); // RSS 2.0 feed
console.log(feed.atom1()); // Atom 1.0 feed
console.log(feed.json1()); // JSON Feed 1.0Main class for creating and managing syndication feeds with support for RSS 2.0, Atom 1.0, and JSON Feed 1.0 formats.
/**
* Class used to generate Feeds
*/
class Feed {
options: FeedOptions;
items: Item[];
categories: string[];
contributors: Author[];
extensions: Extension[];
constructor(options: FeedOptions);
/** Add a feed item */
addItem(item: Item): number;
/** Add a category */
addCategory(category: string): number;
/** Add a contributor */
addContributor(contributor: Author): number;
/** Adds an extension */
addExtension(extension: Extension): number;
/** Returns a Atom 1.0 feed */
atom1(): string;
/** Returns a RSS 2.0 feed */
rss2(): string;
/** Returns a JSON1 feed */
json1(): string;
}Usage Examples:
import { Feed } from "feed";
// Create a feed
const feed = new Feed({
id: "http://example.com/",
title: "My Blog",
description: "A blog about technology",
copyright: "Copyright 2023"
});
// Add content using chainable methods
feed.addItem({
title: "My First Post",
link: "http://example.com/first-post",
date: new Date(),
description: "This is my first blog post"
});
feed.addCategory("Technology");
feed.addContributor({
name: "John Smith",
email: "john@example.com"
});
// Generate feeds in different formats
const rssXml = feed.rss2();
const atomXml = feed.atom1();
const jsonFeed = feed.json1();Configuration options for creating a feed instance.
interface FeedOptions {
/** Unique feed identifier (required) */
id: string;
/** Feed title (required) */
title: string;
/** Copyright notice (required) */
copyright: string;
/** Last updated date */
updated?: Date;
/** Generator software name */
generator?: string;
/** Feed language code */
language?: string;
/** Time-to-live in minutes */
ttl?: number;
/** Feed URL */
feed?: string;
/** Related feed links */
feedLinks?: any;
/** PubSubHubbub hub URL */
hub?: string;
/** Documentation URL */
docs?: string;
/** Whether this is a podcast feed */
podcast?: boolean;
/** Primary feed category */
category?: string;
/** Feed author */
author?: Author;
/** Feed website URL */
link?: string;
/** Feed description */
description?: string;
/** Feed image URL */
image?: string;
/** Feed favicon URL */
favicon?: string;
}Individual entries or articles within a feed.
interface Item {
/** Item title (required) */
title: string;
/** Item URL (required) */
link: string;
/** Item publication date (required) */
date: Date;
/** Unique item identifier */
id?: string;
/** Item summary/description */
description?: string;
/** Full item content */
content?: string;
/** Item categories */
category?: Category[];
/** Globally unique identifier */
guid?: string;
/** Item image */
image?: string | Enclosure;
/** Item audio content */
audio?: string | Enclosure;
/** Item video content */
video?: string | Enclosure;
/** Item enclosure */
enclosure?: Enclosure;
/** Item authors */
author?: Author[];
/** Item contributors */
contributor?: Author[];
/** Published date (different from date) */
published?: Date;
/** Item copyright */
copyright?: string;
/** Item extensions */
extensions?: Extension[];
}Represents an author or contributor to feeds and items.
interface Author {
/** Author's name */
name?: string;
/** Author's email address */
email?: string;
/** Author's website URL */
link?: string;
/** Author's avatar URL */
avatar?: string;
}Feed and item categorization system.
interface Category {
/** Category name */
name?: string;
/** Category domain */
domain?: string;
/** Category scheme */
scheme?: string;
/** Category term */
term?: string;
}Media attachments for podcast feeds and multimedia content.
interface Enclosure {
/** Enclosure URL (required) */
url: string;
/** MIME type */
type?: string;
/** File size in bytes */
length?: number;
/** Enclosure title */
title?: string;
/** Duration in seconds */
duration?: number;
}Usage Examples:
// Simple media enclosure
const audioEnclosure: Enclosure = {
url: "http://example.com/podcast.mp3",
type: "audio/mpeg",
length: 1234567
};
// Podcast episode with duration
const podcastEnclosure: Enclosure = {
url: "http://example.com/episode1.mp3",
type: "audio/mpeg",
length: 8765432,
title: "Episode 1: Getting Started",
duration: 1800 // 30 minutes
};
// Add to feed item
feed.addItem({
title: "Podcast Episode 1",
link: "http://example.com/episode1",
date: new Date(),
enclosure: podcastEnclosure
});Custom extensions for specialized feed functionality.
interface Extension {
/** Extension name (required) */
name: string;
/** Extension data objects */
objects: any;
}Usage Examples:
// Add custom extension
feed.addExtension({
name: "customNamespace",
objects: {
customElement: "customValue",
anotherElement: {
attr: "value",
content: "Custom content"
}
}
});