Task Management System API This is a simple backend API for a task management system built with Node.js, Express.js, and MongoDB. This API allows users to create, read, update, and delete tasks (CRUD operations).
Features Create Task: Adds a new task with validation. Read Tasks: Retrieves a list of all tasks with filtering and sorting options. Read Single Task: Retrieves task details by ID. Update Task: Modifies an existing task. Delete Task: Deletes a task from the database.
Tech Stack Backend: Node.js, Express.js Database: MongoDB with Mongoose Testing: Jest & Supertest
Installation and Setup Prerequisites Node.js (v14 or newer) npm (Node Package Manager)
MongoDB (running locally or through a cloud service like MongoDB Atlas)
Setup Steps Clone the repository:
Bash
git clone https://github.com/your-username/task-management-system.git cd task-management-system Install dependencies:
Bash
npm install Create an environment variables file (.env): Create a .env file in the project root and add the following variables. Replace with your MongoDB connection URI.
PORT=3000 MONGO_URI="mongodb://localhost:27017/task_manager" Run the application:
Bash
npm start The server will run at http://localhost:3000.
https://task-management-api-fch8.onrender.com/tasks
Run tests:
Bash
npm test API Usage Guide
- Create a New Task Endpoint: POST /tasks
Description: Adds a new task to the system.
Request Body:
JSON
{ "title": "Complete Project Report", "description": "Write the final report for the Q3 project.", "category": "Work", "priority": "High", "deadline": "2025-12-31T23:59:59.000Z" } Success Response (201 Created):
JSON
{ "_id": "60d0fe4f5311236168a109ca", "title": "Complete Project Report", "description": "Write the final report for the Q3 project.", "category": "Work", "priority": "High", "deadline": "2025-12-31T23:59:59.000Z", "createdAt": "2025-09-24T12:00:00.000Z", "updatedAt": "2025-09-24T12:00:00.000Z" } Error Response (400 Bad Request):
JSON
{ "message": "Bad Request: Invalid input data.", "details": "Task validation failed: deadline: Deadline must be a future date." } 2. Get All Tasks Endpoint: GET /tasks
Description: Retrieves a list of all tasks with filtering and sorting options.
Query Parameters (Optional):
category (String): Filter by category (e.g., ?category=Personal).
priority (String): Filter by priority (e.g., ?priority=Medium).
sort (String): Sorts the results. Use - for descending order (e.g., ?sort=-deadline or ?sort=priority).
Success Response (200 OK):
JSON
[ { "_id": "60d0fe4f5311236168a109ca", "title": "Complete Project Report", "priority": "High", ... }, { "_id": "60d0fe5f5311236168a109cb", "title": "Weekly Groceries", "priority": "Low", ... } ] 3. Get Task by ID Endpoint: GET /tasks/:id
Success Response (200 OK): Returns a single task object.
Error Response (404 Not Found):
JSON
{ "message": "Not Found: Task with this ID does not exist." } 4. Update Task Endpoint: PUT /tasks/:id
Request Body: JSON object with the fields to be updated.
JSON
{ "priority": "Medium", "description": "The report is halfway done." } Success Response (200 OK): Returns the updated task object.
Error Response (400 or 404): If the data is invalid or the ID is not found.
- Delete Task Endpoint: DELETE /tasks/:id
Success Response (200 OK):
JSON
{ "message": "Task successfully deleted." } Error Response (404 Not Found): If the ID is not found.