This is a small Express API for a card collection. It uses an in-memory array as a mock database, follows a simple controller/service/model structure, and exposes CRUD routes with pagination.
- Express server with CORS and JSON middleware
- CRUD endpoints for cards
- Pagination via
pageandlimitquery params - In-memory data store for quick iteration
4b-me/
├─ index.js
├─ package.json
├─ controllers/
│ └─ card.controller.js
├─ models/
│ └─ card.model.js
├─ routes/
│ └─ card.routes.js
└─ services/
└─ card.service.js
- start: node index.js
- dev: nodemon index.js
- Creates the Express app and registers middleware.
- Defines a base
/route for a welcome message. - Mounts the cards router at
/cards.
- Defines the REST routes and delegates to the controller.
- Handles request/response logic and basic validation.
- Encapsulates pagination and business logic.
- Manages the in-memory card array.
Base URL: http://localhost:3000
- GET /cards
- Query params: page (default 1), limit (default 10)
- Response shape:
{ "totalCards": 1, "totalPages": 1, "currentPage": 1, "limit": 10, "cards": [ { "id": 171836785992, "suit": "diamonds", "value": "queen", "collection": "royal" } ], "next": { "page": 2, "limit": 10 }, "previous": { "page": 1, "limit": 10 } }
- GET /cards/:id
- POST /cards
- Body: { "suit": "hearts", "value": "ace", "collection": "classic" }
- PUT /cards/:id
- Body: any fields to update
- DELETE /cards/:id
- List cards: send a GET request to /cards.
- Paginate: add ?page=2&limit=5 to /cards.
- Fetch one card: GET /cards/:id.
- Create a card: POST /cards with JSON body { "suit": "hearts", "value": "ace", "collection": "classic" }.
- Update a card: PUT /cards/:id with any fields you want to change.
- Delete a card: DELETE /cards/:id.