A small TypeScript REST API built with Express and Mongoose.
This is the REST backend used by the sibling ../rest-graphql comparison client. That client sends GET requests to this server's /events endpoint and expects an array of event objects. Its local REST URI is http://localhost:5000/events.
The sibling ../graphql-server project exposes similar event and user concepts through GraphQL at /api. It is a separate server, not a proxy or runtime dependency of this API. In the Compose stack, both backends use the same MONGO_URI and query the same persisted data.
To use the comparison client's built-in local settings, set PORT=5000 and MONGO_URI, start this API, start the GraphQL server separately on port 8000, and run the frontend. If another port is used, update the REST URI through the frontend Settings dialog. The parent rest-graphql-comparison repository provides a Docker Compose stack with a local MongoDB container and mounts the shared fixture at runtime for GET /eventsLocal.
This project is an early-stage API scaffold centered around events and users.
- The API currently exposes event-related endpoints.
- Event data can be read from MongoDB or, in the Compose stack, from its shared JSON mock fixture.
- User data is modeled in MongoDB but user routes/controllers are not implemented yet.
In short: this is the backend foundation for an event/people app where users can create and manage events.
- Node.js
- TypeScript
- Express
- Mongoose (MongoDB)
- dotenv + envalid for environment configuration
- CORS + JSON body parsing middleware
src/server.ts: Entry point. Loads env, validates env vars, creates app instance, starts server.src/app.ts: Express app setup, middleware registration, controller registration, MongoDB connection.src/interfaces/controller.interface.ts: Shared controller contract (path+router).src/events/event.controller.ts: Event endpoints.src/events/event.model.ts: Mongoose Event schema/model.src/events/event.interface.ts: Event TypeScript interface.src/users/user.model.ts: Mongoose User schema/model.src/users/user.interface.ts: User TypeScript interface.src/utils/validateEnv.ts: Runtime env var validation.
server.tsloads environment variables viadotenv/config.validateEnv()ensures required values are present.Appinitializes:- MongoDB connection
- middleware (
bodyParser.json(),cors()) - registered controllers
EventsControllerexposes the event endpoints under/events.
Returns all events from MongoDB.
Returns the static mock list from the canonical mongo/seed/event-mock-100.json fixture, which Docker Compose mounts read-only into this container. This endpoint is unavailable when the API runs standalone unless that fixture is supplied at the expected runtime path.
Updates an event in MongoDB by ID using the request body. Returns the updated document.
title: string(required)description: string(required)price: number(required)date: Date(required)creator: ObjectId(reference toUser)
email: string(required)password: string(required)name: string(required)createdEvents: ObjectId[](referencesEvent)
Required variables (validated at startup):
PORTMONGO_URI
For example:
mongodb://username:password@host:27017/events?authSource=admin
From package.json:
npm run dev— runs the server withts-node(src/server.ts)npm run build— compiles TypeScript intodistnpm run start— runs compiled output (dist/server.js)
GET /health returns a successful status when the HTTP server is running. Docker Compose uses this endpoint to determine whether the service is ready.
This is a good scaffold, but not production-ready yet. Notable gaps:
- no user routes/controllers yet
- no authentication/authorization
- minimal error handling
- no request validation layer
- no automated tests
- Install dependencies:
npm install-
Create a
.envfile with the required variables. -
Run in development:
npm run dev