Node.js + Express + MongoDB (Mongoose) + Redis caching. Includes JWT auth, Jest tests with mongodb-memory-server and ioredis-mock, and optional Docker setup.
- User signup/login with JWT and bcrypt hashing
- CRUD for tasks scoped to the logged-in user
- Redis caching for
GET /api/tasksper 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
- Node.js >= 18
- MongoDB
- Redis
- Install dependencies:
npm install
- Configure environment. Copy
ENV.EXAMPLEto.envand adjust values:cp ENV.EXAMPLE .env
- Run in development:
npm run dev
Server runs on http://localhost:${PORT} (default 4000).
npm start: start servernpm run dev: start with nodemonnpm test: run testsnpm run test:coverage: run tests with coverage
Swagger UI: Visit http://localhost:4000/api-docs for interactive API documentation.
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..."
}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
GET /health - Check server health
curl http://localhost:4000/healthResponse:
{
"status": "ok"
}Use docker-compose.yml to run API + MongoDB + Redis.
- Tests use mongodb-memory-server and ioredis-mock (no external services required).
- Coverage target ~70%+