The DailyNews backend is a Node.js/TypeScript REST API built with Express and MongoDB. It exposes a set ofDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/miikorz/DailyNews/llms.txt
Use this file to discover all available pages before exploring further.
/feed endpoints for reading, creating, updating, and deleting news articles, and automatically scrapes the top headlines from El País and El Mundo on every GET /feed request. The two key entry points are src/server.ts (bootstrap) and src/app.ts (Express application factory). This page explains how to configure the environment, wire up the database connection, and understand the middleware stack.
Environment Variables
The backend reads its runtime configuration from a.env file in the backend/ directory (loaded via dotenv). Create this file before starting the server.
The TCP port that the Express server listens on. Example:
3000.The MongoDB connection string passed to Mongoose’s
connect() call. Supports both local and Atlas URIs. Example: mongodb://localhost:27017/dailynews.Server Bootstrap
src/server.ts is the process entry point. It loads environment variables with dotenv.config(), establishes the MongoDB connection via connectDB(), and only starts the HTTP listener once the database is ready. If the database connection fails, connectDB() calls process.exit(1) so the server never opens a port without a working database.
Express App Setup
src/app.ts builds and exports the Express application instance. The middleware stack, in registration order, is:
express.urlencoded({ extended: true })— parses URL-encoded form bodies.express.json()— parses JSON request bodies.cors({ origin: '*' })— enables cross-origin requests from any origin.- Global error handler — a four-argument middleware that catches any errors forwarded via
next(err)and returns a structured JSON error response with the appropriate HTTP status code. - Router — the
routerimported fromapi/routes.tsis mounted at/, registering all/feedroutes.
MongoDB Connection
src/infrastructure/database/connect.ts exports a single async function, connectDB(), that uses Mongoose to open a connection to the URI specified in MONGO_URI. On success it logs "MongoDB connected". On failure it logs the error and exits the process with code 1, preventing the server from starting in a broken state.
Available npm Scripts
All scripts are defined inpackage.json and run via npm run <script>.
| Script | Command | Description |
|---|---|---|
dev | nodemon src/server.ts | Start the development server with hot-reload via Nodemon |
build | tsc | Compile TypeScript to dist/ |
start | node dist/server.js | Run the compiled production build |
test | jest | Run the full test suite |
lint | eslint src/*.ts | Lint all TypeScript source files |
lint:fix | eslint src/*.ts --fix | Lint and auto-fix fixable issues |
format | prettier --write "src/**/*.{ts,js,json,md}" | Format all source files with Prettier |
docker:build | docker-compose build | Build Docker images |
docker:up | docker-compose up --watch | Start containers in watch mode |
docker:down | docker-compose down | Stop and remove containers |
docker:restart | docker-compose down && docker-compose up --build | Rebuild and restart all containers |