Blog RSS Feed Generation
Blog RSS feed allows readers to subscribe to new publications. Properly configured feed accelerates search engine indexing and increases audience reach.
Node.js: feed Package
import { Feed } from 'feed';
export async function generateBlogRss(): Promise<string> {
const feed = new Feed({
title: 'MyApp Blog',
description: 'Articles about development and technologies',
id: 'https://example.com',
link: 'https://example.com',
language: 'en',
image: 'https://example.com/logo.png',
favicon: 'https://example.com/favicon.ico',
copyright: `© ${new Date().getFullYear()} MyApp`,
generator: 'MyApp',
feedLinks: {
rss: 'https://example.com/feed',
atom: 'https://example.com/feed/atom',
json: 'https://example.com/feed/json',
},
author: {
name: 'MyApp Editorial',
email: '[email protected]',
link: 'https://example.com/about',
},
});
const posts = await prisma.post.findMany({
where: { published: true },
orderBy: { publishedAt: 'desc' },
take: 50,
include: { author: true, tags: true },
});
posts.forEach(post => {
feed.addItem({
title: post.title,
id: `https://example.com/blog/${post.slug}`,
link: `https://example.com/blog/${post.slug}`,
description: post.excerpt,
content: post.htmlContent,
author: [{ name: post.author.name, email: post.author.email }],
date: post.publishedAt,
image: post.coverImage || undefined,
category: post.tags.map(t => ({ name: t.name })),
});
});
return feed.rss2(); // or feed.atom1(), feed.json1()
}
// Express route
app.get('/feed', async (_req, res) => {
const rss = await generateBlogRss();
res
.type('application/rss+xml')
.set('Cache-Control', 'public, max-age=900')
.send(rss);
});
Next.js: Static RSS on Build
// scripts/generate-rss.ts
import { writeFileSync } from 'fs';
import { generateBlogRss } from '../lib/rss';
async function main() {
const rss = await generateBlogRss();
writeFileSync('./public/feed.xml', rss);
console.log('RSS generated: public/feed.xml');
}
main();
// package.json
{
"scripts": {
"build": "next build && ts-node scripts/generate-rss.ts"
}
}
Feed Validation
Check feed correctness: validator.w3.org/feed. Tool indicates encoding errors, missing required fields, incorrect dates.
Implementation Timeline
RSS feed for blog on Node.js or Laravel: 0.5 days. With JSON Feed, Atom, caching, and autodiscovery: 1 day.







