Skip to content

rahulmishra117/min_task_api

Repository files navigation

Mini Task Tracker API

Node.js + Express + MongoDB (Mongoose) + Redis caching. Includes JWT auth, Jest tests with mongodb-memory-server and ioredis-mock, and optional Docker setup.

Features

  • User signup/login with JWT and bcrypt hashing
  • CRUD for tasks scoped to the logged-in user
  • Redis caching for GET /api/tasks per user; invalidated on create/update/delete
  • Mongoose models with schema validation and indexes
  • Jest tests (unit/integration) and coverage report
  • Swagger/OpenAPI documentation at /api-docs

Requirements

  • Node.js >= 18
  • MongoDB
  • Redis

Setup

  1. Install dependencies:
    npm install
  2. Configure environment. Copy ENV.EXAMPLE to .env and adjust values:
    cp ENV.EXAMPLE .env
  3. Run in development:
    npm run dev

Server runs on http://localhost:${PORT} (default 4000).

Scripts

  • npm start: start server
  • npm run dev: start with nodemon
  • npm test: run tests
  • npm run test:coverage: run tests with coverage

API Documentation

Swagger UI: Visit http://localhost:4000/api-docs for interactive API documentation.

API Endpoints

Authentication

POST /api/auth/signup - Create a new user account

curl -X POST http://localhost:4000/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "john@example.com",
    "password": "password123"
  }'

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

POST /api/auth/login - Authenticate user and get JWT token

curl -X POST http://localhost:4000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john@example.com",
    "password": "password123"
  }'

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Tasks

Note: All task endpoints require authentication. Include the JWT token in the Authorization header:

-H "Authorization: Bearer <your-token>"

GET /api/tasks - Get all tasks for the authenticated user

# Get all tasks
curl -X GET http://localhost:4000/api/tasks \
  -H "Authorization: Bearer <your-token>"

# Filter by status
curl -X GET "http://localhost:4000/api/tasks?status=pending" \
  -H "Authorization: Bearer <your-token>"

# Filter by due date (before)
curl -X GET "http://localhost:4000/api/tasks?dueBefore=2024-12-31T23:59:59Z" \
  -H "Authorization: Bearer <your-token>"

# Filter by due date (after)
curl -X GET "http://localhost:4000/api/tasks?dueAfter=2024-01-01T00:00:00Z" \
  -H "Authorization: Bearer <your-token>"

Response:

[
  {
    "_id": "690b86ecbf00794cd9faee81",
    "title": "My Task",
    "description": "Task description",
    "status": "pending",
    "dueDate": "2024-12-31T23:59:59.000Z",
    "owner": "690b86cdbf00794cd9faee7d",
    "createdAt": "2025-11-05T17:18:36.479Z",
    "updatedAt": "2025-11-05T17:18:36.479Z"
  }
]

POST /api/tasks - Create a new task

curl -X POST http://localhost:4000/api/tasks \
  -H "Authorization: Bearer <your-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Complete project",
    "description": "Finish the task tracker API",
    "status": "pending",
    "dueDate": "2024-12-31T23:59:59Z"
  }'

Response:

{
  "_id": "690b86ecbf00794cd9faee81",
  "title": "Complete project",
  "description": "Finish the task tracker API",
  "status": "pending",
  "dueDate": "2024-12-31T23:59:59.000Z",
  "owner": "690b86cdbf00794cd9faee7d",
  "createdAt": "2025-11-05T17:18:36.479Z",
  "updatedAt": "2025-11-05T17:18:36.479Z"
}

PUT /api/tasks/:id - Update a task

curl -X PUT http://localhost:4000/api/tasks/690b86ecbf00794cd9faee81 \
  -H "Authorization: Bearer <your-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated task title",
    "status": "completed"
  }'

Response:

{
  "_id": "690b86ecbf00794cd9faee81",
  "title": "Updated task title",
  "description": "Finish the task tracker API",
  "status": "completed",
  "dueDate": "2024-12-31T23:59:59.000Z",
  "owner": "690b86cdbf00794cd9faee7d",
  "createdAt": "2025-11-05T17:18:36.479Z",
  "updatedAt": "2025-11-05T17:18:53.622Z"
}

DELETE /api/tasks/:id - Delete a task

curl -X DELETE http://localhost:4000/api/tasks/690b86ecbf00794cd9faee81 \
  -H "Authorization: Bearer <your-token>"

Response: 204 No Content

Health Check

GET /health - Check server health

curl http://localhost:4000/health

Response:

{
  "status": "ok"
}

Docker (optional)

Use docker-compose.yml to run API + MongoDB + Redis.

Notes

  • Tests use mongodb-memory-server and ioredis-mock (no external services required).
  • Coverage target ~70%+

About

Collections of Min Task API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published