tech-news-api
v1.0.0
Published
Installable CLI and API server for aggregated technology news from The Guardian and Hacker News.
Readme
tech-news-api
tech-news-api is an installable Node.js CLI package that launches a production-ready technology news aggregation platform powered by The Guardian Content API and Hacker News Algolia.
It preserves the existing Express API, frontend, caching behavior, category matching, and article normalization while adding a reusable command-line interface.
Features
- Guardian + Hacker News aggregation
- Four canonical categories:
securityai-softwaremobile-devicescloud-infrastructure
- Legacy category aliases:
cybersecuritysmartphonesnetworkingit
- Keyword scoring and exclusion rules
- Latest-first ranking with freshness prioritization
- Stale-while-revalidate caching
- Startup cache warmup
- Search endpoint
- Pagination
- Article detail endpoints
- Generated fallback thumbnails
- Rate limiting
- Centralized error handling
- Responsive frontend served from
/public - Installable CLI with
init,start,doctor, andversion
Installation
Global install:
npm install -g tech-news-apiDirect execution without installing globally:
npx tech-news-apiFor local development in this repository:
npm installQuick Start
Initialize a local .env file in your current working directory:
tech-news-api initStart the server:
tech-news-api startOr just run the default command:
tech-news-apiThe CLI loads .env, validates runtime configuration, and starts the existing server.
CLI Commands
Default command
tech-news-apiStarts the server using your current directory's .env file.
Start
tech-news-api startStarts the existing Express server without changing any API behavior.
Init
tech-news-api initInteractive setup that asks for:
- Guardian API key
- server port
- cache TTL in minutes
It writes:
PORT=5500
GUARDIAN_API_KEY=your_guardian_api_key_here
CACHE_TTL=30If .env already exists, the CLI asks before overwriting it.
Doctor
tech-news-api doctorChecks:
- Node.js version
.envpresence- Guardian API key configuration
- installed runtime dependencies
- configured port availability
Version
tech-news-api version
tech-news-api --versionDisplays the installed package version.
Local Development
Start the app directly from the repository:
npm startDevelopment mode with nodemon:
npm run devEnvironment Variables
Required for full Guardian support:
GUARDIAN_API_KEY
Common:
PORTCACHE_TTL
Optional Open Graph and image tuning:
OG_CACHE_TTL_SECONDSOG_HTTP_TIMEOUT_MSOG_BATCH_CONCURRENCYOG_USER_AGENT
API Overview
The CLI package does not change existing routes.
Category feeds
GET /api/news/all?page=1&limit=10GET /api/news/security?page=1&limit=10GET /api/news/ai-software?page=1&limit=10GET /api/news/mobile-devices?page=1&limit=10GET /api/news/cloud-infrastructure?page=1&limit=10
Legacy aliases still work:
GET /api/news/cybersecurityGET /api/news/smartphonesGET /api/news/networkingGET /api/news/it
Optional query params:
pagelimitrefresh=1since=<unix-ms>
Search
GET /api/search?q=iphone&page=1&limit=10
Article details
GET /api/article/guardian/<encoded-article-path>GET /api/article/hn/<hacker-news-id>
Normalized Article Shape
Every article is normalized to a consistent structure:
articleIdtitledescriptionurlimagefallbackImagecategorysourcepublishedAtarticleBody
Project Structure
API-master/
├── bin/
│ └── tech-news-api.js
├── cache/
├── commands/
│ ├── doctor.js
│ ├── helpers.js
│ ├── init.js
│ ├── start.js
│ └── version.js
├── config/
├── controllers/
├── middleware/
├── public/
├── routes/
├── scripts/
├── services/
├── utils/
├── .env
├── .env.example
├── package.json
├── server.js
└── README.mdNotes
- The existing business logic, routes, frontend behavior, and API responses are preserved.
- The CLI uses CommonJS and is designed to work on Windows, Linux, and macOS.
- The server still supports startup cache warmup, rate limiting, responsive frontend delivery, and generated image fallbacks.
