Building the Website
Relevant source files
The following files were used as context for generating this wiki page:
The website build process is a core feature of the nodejs-news-feeder project, designed to create a user-friendly, static HTML representation of the news feed. The primary goal is to transform the machine-readable feed.xml file into a human-readable index.html page that can be viewed in any web browser. This allows users to consume the latest news without needing an RSS reader.
The entire process is orchestrated by a single Node.js script, which is triggered by an NPM command. This script reads the XML feed, parses its content, injects it into an HTML template using EJS, and writes the final static page to the root of the repository, ready for deployment or local viewing.
Sources: README.md, scripts/build-website.js, package.json:18
Build Process Overview
The website generation is a linear, multi-step process executed by the website:build NPM script. It leverages helper functions to interact with the filesystem and uses third-party libraries for parsing and templating.
The following diagram illustrates the data flow from executing the script to generating the final index.html file.
This diagram shows the sequence of operations within the scripts/build-website.js script, including reading the XML feed and EJS template, parsing the feed, rendering the HTML, and writing the final output to index.html.
Sources: scripts/build-website.js, utils/index.js:10-12, 185-187, 193-195
Key Components
The build system is composed of several key files and modules that work together.
NPM Script
The process is initiated via an NPM script defined in package.json.
| Script | Command | Description |
|---|---|---|
website:build | node scripts/build-website.js | Executes the main build script to generate index.html. |
Sources: package.json:18
Build Script (scripts/build-website.js)
This is the main script that orchestrates the entire build process. It imports necessary utilities, reads the source files, processes the data, and writes the output.
The script performs the following actions:
- Imports
getFeedContent,overwriteWebsiteContent, andgetWebsiteTemplatefromutils/index.js. - Reads the EJS template and the XML feed content.
- Uses the
@ulisesgascon/rss-feed-parserlibrary to parse the XML string into a JavaScript object containingmetadataand an array ofitems. - Renders the EJS template, passing the parsed
metadataanditemsto it. - Writes the resulting HTML content to
index.htmlin the project's root directory.
// scripts/build-website.js:1-13
import { getFeedContent, overwriteWebsiteContent, getWebsiteTemplate } from '../utils/index.js'
import ejs from 'ejs'
import { rssParse } from '@ulisesgascon/rss-feed-parser'
const template = getWebsiteTemplate()
const feed = getFeedContent()
try{
const { metadata, items } = rssParse(feed)
console .log(items)
const html = ejs.render(template, { metadata, items:items.map((e)=>{
e.link.replace('https://thomas-iniguez-visioli.github.io/nodejs-news-feeder/','')
return e
}) })
overwriteWebsiteContent(html)
}catch(err){console.log(err)}
The following sequence diagram details the interactions between the build script and the utility module.
Sources: scripts/build-website.js
Utility Functions (utils/index.js)
The utils/index.js module provides helper functions for file system operations, abstracting the direct file paths and read/write logic from the main build script.
| Function | Description | Source File Path |
|---|---|---|
getFeedContent() | Reads and returns the content of feed.xml. | feed.xml |
getWebsiteTemplate() | Reads and returns the content of the EJS template. | templates/index.html.ejs |
overwriteWebsiteContent(content) | Writes the provided HTML content to index.html. | index.html |
Sources: utils/index.js:185-187, 189-191, 193-195
Website Template and Output
The build process uses an EJS (Embedded JavaScript) template located at templates/index.html.ejs. This file is not directly provided, but its path is defined in utils/index.js. The script injects the parsed feed items into this template.
The final output is index.html, a static HTML file. Based on the provided example, the structure of a rendered news item is as follows:
<!-- index.html:202-214 -->
<hr>
<article>
<h3>
Operation Endgame 3.0 - 2,046,030 breached accounts
</h3>
Between 10 and 13 November 2025, <a href="https//www.europol.europa.eu/media-press/newsroom/news/end-of-game-for-cybercrime-infrastructure-1025-servers-taken-down" target="_blank" rel="noopener">the latest phase of Operation Endgame was coordinated from Europol's headquarters in The Hague</a>. The actions targeted one of the biggest infostealer Rhadamanthys, the Remote Access Trojan VenomRAT, and the botnet Elysium, all of which played a key role in international cybercrime. Authorities took down these three large cybercrime enablers and provided 2 million impacted email addresses and 7.4 million passwords to HIBP.</p>
<p class="feed-time">
Thu, 13 Nov 2025 10:23:00 GMT
</p>
<a class="feed-link" href="https//haveibeenpwned.com/Breach/OperationEndgame3">
read more
</a>
</article>
Each item is rendered inside an <article> tag, containing the title, description, publication date, and a link to the original source.
Sources: utils/index.js:11-12, index.html, scripts/build-website.js:8-12
Serving the Website Locally
For development and testing, the project includes a simple Express server defined in server.js. This server can be used to view the generated index.html file.
The server is configured to serve all static files from the project's root directory.
// server.js:9
app.use(express.static(process.cwd()));
This means that after running npm run website:build, you can start the server with npm start and navigate to http://localhost:3000/index.html to see the generated website. The server also provides an interface at the root (/) for manually adding posts via add-post.html.
Sources: server.js:5, 9, 11-13, package.json:13
Conclusion
The website build process is a vital part of the nodejs-news-feeder project, providing an accessible and user-friendly way to view the aggregated news. By using a template-based approach with EJS and a simple Node.js script, the system efficiently converts the raw feed.xml data into a polished, static index.html page. This separation of data collection and presentation ensures a robust and maintainable architecture.
Sources: README.md, scripts/build-website.js