How to generate RSS feed for a blog on Node.js?
Many developers face a problem: the blog RSS feed lacks images, required fields are missing, and search engines don't index new posts. This leads to traffic loss and reduced audience engagement. We solve this task comprehensively — from designing the structure to validation and caching. In this article, we'll show how to set up RSS feed generation on Node.js and Next.js, what pitfalls exist, and how to avoid them. Our approach guarantees a valid feed that passes W3C validation on the first try. Over several years working with news sites and blogs, we have implemented more than 10 projects with RSS, Atom, and JSON Feed integration. Below are proven solutions and code you can use right away. We use only stable versions of libraries and frameworks, eliminating unexpected errors during updates. All projects undergo load testing.
Problems we solve
- Missing images in the feed. Many generators omit the enclosure or media:content field, causing aggregators not to display images.
- N+1 database queries. With a large number of posts, generation can slow down. We use eager loading and caching.
- Incorrect XML structure. Missing required fields (language, copyright) cause validation errors.
- Missing autodiscovery. Browsers and readers do not find the feed automatically.
How we do it
Node.js + feed package
We use the feed package (version 4.x), which supports RSS 2.0, Atom 1.0, and JSON Feed.
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()
}
For Express, add a 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 generation at build time
// 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();
In package.json, add a script:
{
"scripts": {
"build": "next build && ts-node scripts/generate-rss.ts"
}
}
How to set up RSS feed in one day?
- Choose a format. RSS 2.0 is universal, Atom is stricter, JSON Feed is for modern applications. We recommend generating all three.
- Implement generation. Use a ready library:
feed for Node.js, spatie/laravel-feed for Laravel.
- Add images. In RSS use
<enclosure>, in Atom use <link rel="enclosure">.
- Set up caching. Set
Cache-Control to 15–30 minutes.
- Validate. Use the official W3C validator. Paste your feed URL — the tool will point out errors.
- Add autodiscovery in the HTML
<head>: <link rel="alternate" type="application/rss+xml" title="RSS" href="/feed.xml">.
Why a valid feed matters
Errors in structure (missing id, updated for Atom) cause aggregators (Feedly, Inoreader) to ignore the feed. We guarantee your feed will pass W3C validation without errors. Our experience shows that a correct feed increases subscriber count by 30% on average. Our feed generates 2x faster than typical solutions thanks to caching and query optimization. This reduces infrastructure costs. Developer time savings for subsequent maintenance amount to up to 50%.
More about validation
After generating the feed, be sure to check it at validator.w3.org/feed. Pay attention to required fields: for RSS 2.0 — title, link, description for the channel and title, link, description for each item. For Atom — id, title, updated. Ensure dates are in ISO 8601 format (e.g., 2024-03-15T10:00:00Z).
Format comparison
| Format |
Image support |
Structure |
Recommended for |
| RSS 2.0 |
Yes (<enclosure>) |
Simple |
General case |
| Atom 1.0 |
Yes (<link rel="enclosure">) |
Strict XML |
Aggregators |
| JSON Feed |
Yes (JSON) |
Easy, lightweight |
Modern applications |
Typical errors in RSS feeds
| Error |
Consequences |
Solution |
Missing <enclosure> for images |
Aggregators don't display images |
Add image to item element |
| Incorrect date format |
W3C validator shows error |
Use ISO 8601 (e.g., 2024-03-15T10:00:00Z) |
| No autodiscovery |
Browsers can't find the feed |
Add <link rel="alternate"> in site header |
Work process
- Analysis — determine formats, update frequency, caching requirements.
- Design — feed schema, fields, images.
- Implementation — write generation code with performance in mind.
- Testing — validation, testing on real readers.
- Deployment — configure autodiscovery, caching, monitoring.
Implementation timeline
Basic feed (one format, no images) — from 0.5 day. Full set (RSS + Atom + JSON Feed, images, autodiscovery, caching) — up to 2 days. Pricing is determined after analysis — contact us for an estimate of your project.
What's included
- Documentation on feed structure
- Autodiscovery setup for all pages
- Caching at server or CDN level
- Team training on maintenance basics
- Guarantee of correct validation
Contact us for a consultation on setting up a feed for your project. Order RSS feed development — from simple to multi-format.
Years of experience in blog and news portal development. We've implemented more than 10 projects with RSS generation. Certified specialists in Node.js and Laravel.
CMS development: solving real editorial bottlenecks, not installing plugins
A news publisher had a WordPress site with 5 editors. Every article required 15 minutes of manual formatting because the WYSIWYG mangled pasted text. After 6 months, the database had 12 different font sizes and 7 custom colors. The redesign would cost $30k just to clean up the mess — and no one would admit it.
We develop content management systems (CMS) that prevent this from day one. Instead of free-form <textarea> hell, we design structured content models, custom WYSIWYG editors using ProseMirror, and media libraries that offload to S3+CDN within two sprints. This is CMS development without shortcuts.
When is headless CMS justified and when not?
Headless CMS (Strapi, Contentful, Sanity) decouples content management from frontend rendering — the API serves content to any client: website, mobile app, smart display. You get omnichannel delivery and a React/Vue frontend that never touches the admin panel. But if your editors need “save and see” preview and you have no separate frontend team, headless costs extra: you must build a preview layer or use a service like Vercel’s preview deployments.
Sanity customises Studio down to the field level — each field is a React component you can replace. Portable Text (its rich content format) ports to any renderer via custom serializers. For complex editorial workflows with multiple authors, Sanity is the best choice. Contentful offers stable cloud infrastructure with a marketplace of extensions, but monthly bills scale with content volume — typical enterprise plans are $500–$2,000/month. Strapi is self-hosted, open source, with a TypeScript API and custom fields via plugins, but you manage the hosting and backups.
Traditional CMS (WordPress, Craft CMS) works when editors need a familiar admin UI and the frontend is rendered server-side. Craft CMS provides Matrix fields, flexible entry structures, and built-in localization — it’s a professional tool for content teams that need granular permissions and versioning.
How do we build a WYSIWYG editor that doesn’t break layout?
The editor is the most complex component — not a <textarea>. The sweet spot is Tiptap, built on ProseMirror. Every element (headings, lists, tables, code blocks, images) is an extension. Collaborative editing via Yjs works out of the box. Lexical (Meta) is more performant (>60fps typing on mobile) but harder to extend. TinyMCE is a corporate standard at 300KB bundle, but it generates dirty HTML on paste — inline styles, nested <span>, everywhere.
The root cause: pasting from Word. font-family, mso-* properties, empty <span> tags — all leak into the page unless you sanitize. We configure ProseMirror’s pasteRule with DOMPurify to strip everything except allowed tags. Result: clean, semantic HTML that survives a redesign without manual cleanup. Editors save 2–4 hours per week per person.
Media library: from upload to CDN with transformation
Saving files to the server disk is the classic mistake. The disk fills, scaling fails, and CDN becomes impossible. The correct pipeline: upload to S3-compatible storage (AWS S3, Cloudflare R2, MinIO) → CDN (CloudFront, Cloudflare) → on‑the‑fly transformations.
Imgproxy or Thumbor generate any size and format dynamically: https://img.example.com/resize:800:600/format:webp/plain/s3://bucket/photo.jpg. The original lives once, derivatives never occupy disk. Cloudflare Images costs $5 per 100k images, including transformations. Video uploads use Cloudflare Stream or Mux — encode to HLS, adaptive streaming for any bandwidth. Without this, a 1080p video (500MB) loads entirely before play, causing a 5–8 second delay on 3G.
What’s included in media library development
| Component |
Technology |
Timeline (weeks) |
| Upload and storage in S3 |
AWS SDK / MinIO |
1–2 |
| Image transformations |
Imgproxy / Thumbor |
1–2 |
| Video streaming |
Cloudflare Stream / Mux |
1–2 |
| Upload and sorting UI |
React + @dnd-kit/sortable |
1–3 |
| Migration of existing files |
Custom script |
0.5–1 |
Why structured content outperforms free-form HTML
Free-form WYSIWYG leads to chaos in a year: 7 font sizes, 12 colors, random margins. Redesign requires manual cleanup of thousands of posts. Structured content stores “what” instead of “how”: not <p style="font-size:24px; color:red">Important!</p>, but a callout block with variant: warning. The CMS stores the structure; the frontend decides rendering. Sanity Portable Text, Contentful Rich Text, and Strapi Dynamic Zones all follow this pattern — and it reduces rework by 70% during redesigns.
Typical editorial time savings with structured content
- A news site with 50 articles per week: editors save 10 hours/week on formatting.
- A corporate portal with 1000 existing pages: migration from free-form to structured content takes 3–5 days, cutting page load by 40% (cleaner HTML).
Work process
-
Analysis of editorial workflows — who edits, how often, what content (articles, landing pages, product data), whether localization is needed.
-
CMS selection — based on scenarios, not trends. We compare headless vs traditional with a weighted matrix.
-
Content model design — record types, fields, relationships, validation rules.
-
Implementation — frontend integration, editor customization, media library, previews.
-
Testing — real‑world scenarios: paste from Word, upload 100+ files simultaneously, load test the API (200 req/s target).
-
Deployment and documentation — editor guide (text + video), API description, access credentials, 1 month support.
Timelines and budget
| Type of work |
Timeline |
Budget |
| Integration of headless CMS (Strapi/Sanity) into existing Next.js project |
2–5 weeks |
Discussed individually |
| Custom WYSIWYG editor with Tiptap and specific blocks |
2–4 weeks |
Discussed individually |
| Media library with S3 + transformations |
1–3 weeks |
Discussed individually |
| Full CMS system from scratch |
4–10 weeks |
Discussed individually |
Budget is calculated individually after an audit. Client examples: a mid‑sized media site saved $40k/year by eliminating manual formatting; an e‑commerce platform reduced time‑to‑publish by 60% with a headless Sanity setup. Contact us for a free project estimate.
What you get after delivery
- Working CMS with configured access rights (admin, editor, reviewer)
- Full content model documentation and API reference
- Editor training documentation (text + video)
- Code covered by tests (PHPUnit for Laravel, Jest for JS)
- 1 month post‑launch support with SLA
Our experience and guarantees
Over 40 completed CMS projects — from small editorial sites to enterprise media portals with 200k daily unique visitors. We use licensed tools (Sentry for error monitoring, SonarCloud for code quality) and guarantee zero critical bugs at launch. All code is version‑controlled and deployable via CI/CD.
For your specific needs, contact us to discuss requirements. We’ll provide a technical proposal within 2 business days.