A clean, modular RESTful API for managing tasks, built with Node.js, Express, and MongoDB.
Supports task creation, listing, updating, deleting, filtering, and robust error handling.
- View all tasks
- Add a new task
- Mark a task as completed
- Delete a task
- Filter tasks by completion status (
completed=trueorcompleted=false) - Async error handling with clear responses
backend/
├── config/
│ └── db.js
├── controllers/
│ └── taskController.js
├── models/
│ └── Task.js
├── routes/
│ └── taskRoutes.js
├── app.js
├── package.json
└── README.md
git clone https://github.com/your-username/your-repo.git
cd backendnpm install- Make sure MongoDB is running locally, or update the
mongoURIinapp.jsto your remote/cloud connection string.
node app.jsThe API will be available at http://localhost:5000/
GET /api/tasks
GET /api/tasks?completed=true
GET /api/tasks?completed=false
POST /api/tasks
Content-Type: application/json
{
"title": "Your task title"
}
PUT /api/tasks/:id
DELETE /api/tasks/:id
# Get all tasks
curl http://localhost:3000/api/tasks
# Get only completed tasks
curl http://localhost:3000/api/tasks?completed=true
# Add a new task
curl -X POST http://localhost:3000/api/tasks -H "Content-Type: application/json" -d '{"title": "Learn Express"}'
# Mark a task as completed
curl -X PUT http://localhost:3000/api/tasks/<task_id>
# Delete a task
curl -X DELETE http://localhost:3000/api/tasks/<task_id>- Validation: Task title must not be empty.
- Filtering: Use the
completedquery parameter to filter by status. - Error Handling: All endpoints return appropriate status codes and error messages.
MIT
Built with ❤️ by Eyasu Getaneh