- You have learned the basics of Node.js and Express.js, now let's test your knowledge of how to setup API endpoints with this Task Management project.
- Clone this project repository in your terminal
- CD into the project base directory
cd Week18_Task_Management_NodeJS
- Install dependencies:
npm install
- Start the server:
npm start
- The server will run on
http://localhost:3000
The project currently has a basic task management API with the following structure:
Main Task Operations:
GET /api/tasks
- Get all tasks (with filtering by status, priority, assignedTo)GET /api/tasks/:id
- Get task by IDPOST /api/tasks
- Create new task⚠️ YOU NEED TO COMPLETE THISPUT /api/tasks/:id
- Update entire task⚠️ YOU NEED TO COMPLETE THISDELETE /api/tasks/:id
- Delete specific task⚠️ YOU NEED TO COMPLETE THIS
Each task has the following structure:
{
"id": "1",
"title": "Task Title",
"description": "Task description",
"status": "pending|in-progress|completed|cancelled",
"priority": "low|medium|high|urgent",
"dueDate": "2024-01-15",
"assignedTo": "John Doe",
"subtasks": [
{
"id": "1.1",
"title": "Subtask Title",
"description": "Subtask description",
"completed": false
}
],
"createdAt": "2024-01-01T10:00:00.000Z",
"updatedAt": "2024-01-01T10:00:00.000Z"
}
You need to complete the following endpoints in routes/tasks.js
:
Location: routes/tasks.js
around line 152
- Implement the logic to create a new task
- Validate required fields (title, description, status, priority)
- Generate a new ID for the task
- Add timestamps (createdAt, updatedAt)
- Save the task to the JSON file
Location: routes/tasks.js
around line 181
- Implement the logic to update an existing task
- Find the task by ID
- Replace the entire task with new data
- Update the updatedAt timestamp
- Save changes to the JSON file
Location: routes/tasks.js
around line 350
- Implement the logic to delete a task
- Find the task by ID
- Remove the task from the array
- Save changes to the JSON file
You can use Postman to test your endpoints.
Objective: Add user information to each task to track who created it.
Requirements:
-
Update the task data structure in
data/tasks.json
to include:{ "createdBy": { "id": "1", "name": "John Doe", "email": "john@example.com" }, "assignedBy": { "id": "2", "name": "Jane Smith", "email": "jane@example.com" } }
-
Update the POST endpoint to include user information:
- Add
createdBy
field to new tasks - Validate user information
- Include user details in the response
- Add
-
Update the PUT endpoint to handle user changes:
- Allow updating
assignedBy
information - Track who made the last update
- Include user information in the response
- Allow updating
-
Add user filtering to the GET endpoint:
- Filter tasks by
createdBy
user - Filter tasks by
assignedBy
user - Add query parameters like
?createdBy=1
or?assignedBy=2
- Filter tasks by
Example API calls for stretch goals:
# Create task with user information
curl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-d '{
"title": "Task with User",
"description": "This task includes user info",
"status": "pending",
"priority": "medium",
"createdBy": {
"id": "1",
"name": "John Doe",
"email": "john@example.com"
}
}'
# Get tasks by user
curl "http://localhost:3000/api/tasks?createdBy=1"
By completing this project, you will demonstrate understanding of:
- RESTful API Design - Proper endpoint naming and HTTP methods
- Data Validation - Input validation and sanitization
- Error Handling - HTTP status codes and error responses
- File Operations - Reading and writing JSON files
- Express.js Routing - Route parameters and query strings
- Async/Await - Handling asynchronous operations
- Complete the POST endpoint for creating tasks
- Complete the PUT endpoint for updating tasks
- Complete the DELETE endpoint for removing tasks
- Test all endpoints using curl or Postman
- Optional: Implement stretch goals with user information
- Check the existing code - Study the GET endpoints for patterns
- Read the comments - Look for TODO comments in the code
- Test frequently - Test each endpoint as you build it
- Ask questions - Don't hesitate to ask for clarification
Good luck with your implementation! 🚀