Subscription Tracker is an Express-based REST API for managing user accounts and their recurring subscriptions. It uses MongoDB with Mongoose for persistence and JWT for authentication tokens.
- User registration with password hashing and JWT issuance
- Basic sign-in and sign-out endpoints (placeholders for future enhancements)
- Subscription model with validation for frequency, renewal dates, and categorisation
- Centralised error handling middleware for consistent API responses
- Node.js 22.x (LTS) and npm
- A MongoDB instance (Atlas or self-hosted)
- Whitelisted IP or VPN access if connecting to MongoDB Atlas
- Install dependdencies:
npm install
- Create an environment file based on
.env.development.localand adjust the values as needed:Update the copied file with your secrets (see Environment Variables).cp .env.development.local .env.development.local
- Start the development server with hot reload:
The API is available at
npm run dev
http://localhost:5000by default.
The app loads environment variables from .env.<NODE_ENV>.local. For development, populate .env.development.local with:
|
MongoDB Atlas tip: Ensure your machine's IP address is added to the Atlas Network Access allowlist, otherwise connections will fail with
MongooseServerSelectionError.
app.js
config/
env.js
controllers/
auth.controller.js
middlewares/
error.middleware.js
models/
subscription.model.js
user.model.js
routes/
auth.routes.js
subscription.routes.js
user.routes.js
databse/
mongodb.js
npm run dev– start the API with nodemon for automatic restart on changesnpm start– run the API once using Node
POST /api/v1/auth/sign-up– create a new user accountPOST /api/v1/auth/sign-in– placeholder for user loginPOST /api/v1/auth/sign-out– placeholder for session terminationGET /api/v1/users– fetch all users (stub response)POST /api/v1/users– create user (stub response)GET /api/v1/users/:id– fetch a user by id (stub response)PUT /api/v1/users/:id– update a user (stub response)DELETE /api/v1/users/:id– delete a user (stub response)GET /api/v1/subscriptions– list subscriptions (stub response)GET /api/v1/subscriptions/:id– get subscription details (stub response)POST /api/v1/subscriptions– create subscription (stub response)PUT /api/v1/subscriptions– update subscriptions (stub response)DELETE /api/v1/subscriptions– delete subscriptions (stub response)GET /api/v1/subscriptions/user/:id– get subscriptions for a user (stub response)PUT /api/v1/subscriptions/:id/cancel– cancel a subscription (stub response)
All unhandled errors are processed by middlewares/error.middleware.js, which standardises responses for validation issues, duplicate keys, casting errors, and unexpected exceptions.
- Implement full authentication flow (sign-in, sign-out) and secure protected routes
- Flesh out subscription controller logic and integrate with
Subscriptionmodel - Add unit/integration tests and CI linting
- Document detailed API schemas (OpenAPI/Swagger) once endpoints stabilise