A RESTful API for managing tasks, built with Node.js, Express, and MongoDB.
- Create, read, update, and delete tasks
- Filter tasks by status, priority, and due date
- User authentication and authorization
- Password reset functionality
- Categorize tasks for better organization
- Simple and intuitive API endpoints
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT Authentication
- Docker
- Node.js (v14 or higher)
- MongoDB (local or Atlas)
- Docker and Docker Compose (for Docker setup)
- Clone the repository:
git clone <repository-url>
cd task-management-api
- Install dependencies:
npm install
- Create a
.envfile in the root directory with the following variables:
PORT=5000
MONGO_URI=mongodb://localhost:27017/task-management
NODE_ENV=development
JWT_SECRET=your_jwt_secret
Note: Update the MONGO_URI with your MongoDB connection string and use a strong JWT_SECRET.
- Clone the repository:
git clone <repository-url>
cd task-management-api
- Create a
.envfile in the root directory with your environment variables:
PORT=5000
MONGO_URI=mongodb://localhost:27017/task-management
NODE_ENV=development
JWT_SECRET=your_secure_jwt_secret
- Run the application using Docker Compose:
docker-compose up
This will start both the API server and MongoDB. The API will be available at http://localhost:5000.
Security Note: The docker-compose.yml file uses environment variables from your local
.envfile. Never commit the.envfile or any file containing secrets to version control.
npm run dev
npm start
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/users | Register a new user |
| POST | /api/auth/login | Login a user |
| GET | /api/users/me | Get user profile (requires authentication) |
| POST | /api/auth/forgotpassword | Request password reset |
| PUT | /api/auth/resetpassword/:resettoken | Reset password |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/tasks | Get all tasks (requires authentication) |
| POST | /api/tasks | Create a new task (requires authentication) |
| GET | /api/tasks/:id | Get a task by ID (requires authentication) |
| PUT | /api/tasks/:id | Update a task (requires authentication) |
| DELETE | /api/tasks/:id | Delete a task (requires authentication) |
| GET | /api/tasks/category/:categoryId | Get tasks by category (requires authentication) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/categories | Get all categories (requires authentication) |
| POST | /api/categories | Create a new category (requires authentication) |
| DELETE | /api/categories/:id | Delete a category (requires authentication) |
Request:
{
"name": "John Doe",
"email": "john@example.com",
"password": "123456"
}Response:
{
"_id": "60f7b0b9e6d3f41a94a3e945",
"name": "John Doe",
"email": "john@example.com",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Request:
{
"email": "john@example.com",
"password": "123456"
}Response:
{
"_id": "60f7b0b9e6d3f41a94a3e945",
"name": "John Doe",
"email": "john@example.com",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
[
{
"_id": "60f7b0b9e6d3f41a94a3e943",
"title": "Complete project",
"description": "Finish the task management API project",
"status": "in-progress",
"priority": "high",
"dueDate": "2023-07-20T00:00:00.000Z",
"createdAt": "2023-07-15T12:34:56.789Z",
"updatedAt": "2023-07-16T09:12:34.567Z",
"user": "60f7b0b9e6d3f41a94a3e945",
"category": {
"_id": "60f7b0b9e6d3f41a94a3e946",
"name": "Work",
"color": "#0275d8"
}
},
...
]Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request:
{
"title": "Read documentation",
"description": "Read Express.js documentation",
"status": "pending",
"priority": "medium",
"dueDate": "2023-07-25",
"category": "60f7b0b9e6d3f41a94a3e946"
}Response:
{
"_id": "60f7b0b9e6d3f41a94a3e944",
"title": "Read documentation",
"description": "Read Express.js documentation",
"status": "pending",
"priority": "medium",
"dueDate": "2023-07-25T00:00:00.000Z",
"createdAt": "2023-07-15T13:45:12.345Z",
"updatedAt": "2023-07-15T13:45:12.345Z",
"user": "60f7b0b9e6d3f41a94a3e945",
"category": {
"_id": "60f7b0b9e6d3f41a94a3e946",
"name": "Work",
"color": "#0275d8"
}
}Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
[
{
"_id": "60f7b0b9e6d3f41a94a3e946",
"name": "Work",
"color": "#0275d8",
"user": "60f7b0b9e6d3f41a94a3e945",
"createdAt": "2023-07-15T10:24:56.789Z",
"updatedAt": "2023-07-15T10:24:56.789Z"
},
{
"_id": "60f7b0b9e6d3f41a94a3e947",
"name": "Personal",
"color": "#5cb85c",
"user": "60f7b0b9e6d3f41a94a3e945",
"createdAt": "2023-07-15T10:25:36.789Z",
"updatedAt": "2023-07-15T10:25:36.789Z"
}
]Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request:
{
"name": "Study",
"color": "#f0ad4e"
}Response:
{
"_id": "60f7b0b9e6d3f41a94a3e948",
"name": "Study",
"color": "#f0ad4e",
"user": "60f7b0b9e6d3f41a94a3e945",
"createdAt": "2023-07-15T13:50:45.678Z",
"updatedAt": "2023-07-15T13:50:45.678Z"
}Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
[
{
"_id": "60f7b0b9e6d3f41a94a3e949",
"title": "Learn MongoDB",
"description": "Study MongoDB aggregation",
"status": "pending",
"priority": "high",
"createdAt": "2023-07-15T14:15:32.123Z",
"updatedAt": "2023-07-15T14:15:32.123Z",
"user": "60f7b0b9e6d3f41a94a3e945",
"category": {
"_id": "60f7b0b9e6d3f41a94a3e948",
"name": "Study",
"color": "#f0ad4e"
}
},
...
]