Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pintu544/task-management
Creating a RESTful API for managing tasks. The API should allow users to create, read, update, and delete tasks. Each task should have a title, description, status (e.g., "in progress," "completed"), and a due date. Users should be able to sign up, log in, and only manage their own tasks.
https://github.com/pintu544/task-management
expressjs mongodb nodejs
Last synced: 6 days ago
JSON representation
Creating a RESTful API for managing tasks. The API should allow users to create, read, update, and delete tasks. Each task should have a title, description, status (e.g., "in progress," "completed"), and a due date. Users should be able to sign up, log in, and only manage their own tasks.
- Host: GitHub
- URL: https://github.com/pintu544/task-management
- Owner: pintu544
- Created: 2023-10-02T10:08:21.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-02T10:13:26.000Z (about 1 year ago)
- Last Synced: 2024-04-15T08:28:03.326Z (8 months ago)
- Topics: expressjs, mongodb, nodejs
- Language: JavaScript
- Homepage: https://task-management-pintu870.vercel.app
- Size: 594 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Node.js RESTful API for Todo App with JWT AuthenticationThis project is a Node.js based RESTful API that allows users to manage tasks in a TODO app. Users can create, read, update, and delete tasks. The API implements JWT authentication to secure the endpoints, ensuring that only authenticated users can perform CRUD operations on their tasks.
## Installation
To run this project on your local machine, follow these steps:
1. **Clone the repository:**
```bash
git clone [](https://github.com/pintu544/Task-Management)
```2. **Install dependencies:**
```bash
cd Task-Management
npm install
```3. **Set environment variables:**
Create a `.env` file in the root directory of the project and add the following variables:
```plaintext
PORT=8000
MONGO_URI="mongodb://localhost:TaskManagement"
JWT_SECRET=secretkey
```4. **Run the application:**
```bash
npm start
```You can now access the API at `http://localhost:8000`.
## Endpoints
### Authentication
#### Sign Up
- **Endpoint:** `POST /signup`
[![image](https://www.linkpicture.com/q/Sign-Up.png)](https://www.linkpicture.com/view.php?img=LPic651a94006ccf51863587255)
Creates a new user account.**Request Body:**
```json
{
"email": "[email protected]",
"password": "password",
"role": "admin" or "user"
}
```**Response:**
```json
{
"user": {
"_id": "6158c8230a5f6ecb12345678",
"email": "[email protected]"
},
"token": ""
}
```#### Sign In
- **Endpoint:** `POST /signin`
[![image](https://www.linkpicture.com/q/Sign-In_1.png)](https://www.linkpicture.com/view.php?img=LPic651a94006ccf51863587255)
Logs in a user and returns a JWT token.**Request Body:**
```json
{
"email": "[email protected]",
"password": "password"
}
```**Response:**
```json
{
"token": ""
}
```### Tasks
#### Create Task
- **Endpoint:** `POST /create-todo`
[![image](https://www.linkpicture.com/q/sCreate-Task.png)](https://www.linkpicture.com/view.php?img=LPic651a94006ccf51863587255)
Creates a new task.
**Request Body:**
```json
{
"taskName": "Task 1",
"taskDescription": "Do something",
"taskStatus": "in progress"
}
```**Response:**
```json
{
"_id": "6158c8230a5f6ecb12345679",
"taskName": "Task 1",
"taskDescription": "Do something",
"taskStatus": "in progress",
"createdAt": "2023-04-22T10:55:50.177Z",
"updatedAt": "2023-04-22T10:55:50.177Z",
"__v": 0
}
```#### Get All Tasks
- **Endpoint:** `GET /todo`
[![image](https://www.linkpicture.com/q/All-Task.png)](https://www.linkpicture.com/view.php?img=LPic651a94006ccf51863587255)
Gets all tasks for the authenticated user.
**Response:**
```json
[
{
"_id": "6158c8230a5f6ecb12345679",
"taskName": "Task 1",
"taskDescription": "Do something",
"taskStatus": "in progress",
"createdAt": "2023-04-22T10:55:50.177Z",
"updatedAt": "2023-04-22T10:55:50.177Z"
},
{
"_id": "6158c8230a5f6ecb1234567a",
"taskName": "Task 2",
"taskDescription": "Do something else",
"taskStatus": "completed",
"createdAt": "2023-04-22T10:56:23.177Z",
"updatedAt": "2023-04-22T10:56:23.177Z"
}
]
```#### Get Task by ID
- **Endpoint:** `GET /todo/:id`
Gets a task by ID.
**Response:**
```json
{
"_id": "6158c8230a5f6ecb12345679",
"taskName": "Task 1",
"taskDescription": "Do something",
"taskStatus": "in progress",
"createdAt": "2023-04-22T10:55:50.177Z",
"updatedAt": "2023-04-22T10:55:50.177Z"
}
```#### Update Task
- **Endpoint:** `PATCH /tasks/:id`
[![image](https://www.linkpicture.com/q/sUpdate-Task.png)](https://www.linkpicture.com/view.php?img=LPic651a94006ccf51863587255)
Updates a task by ID.
**Request Body:**
```json
{
"description": "Do something else",
"status": "completed"
}
```**Response:**
```json
{
"_id": "6158c8230a5f6ecb12345679",
"taskName": "New Task Name",
"taskDescription": "Do something else",
"taskStatus": "completed",
"createdAt": "2023-04-22T10:55:50.177Z",
"updatedAt": "2023-04-22T11:05:34.447Z"
}
```#### Delete Task
- **Endpoint:** `DELETE /todo/:id`
[![image](https://www.linkpicture.com/q/sDelete-Task.png)](https://www.linkpicture.com/view.php?img=LPic651a94006ccf51863587255)
Deletes a task by ID.
**Response:**
```json
{
"message": "Task deleted successfully"
}
```## Error Handling
The API returns appropriate HTTP status codes and error messages for various scenarios such as invalid input, unauthorized access, and server errors.
## Authentication
The API uses JWT authentication to secure the endpoints and ensure that only authenticated users can perform CRUD operations on their tasks.
## Additional Features Implemented
1. **Pagination:** The `GET /tasks` endpoint supports pagination using the `page` and `limit` query parameters.
2. **Filtering:** The `GET /tasks` endpoint supports filtering by task status using the `status` query parameter.## Conclusion
This project demonstrates how to build a RESTful API with Node.js and Express, implement JWT authentication, and use MongoDB as the database. The API provides basic CRUD operations for tasks and includes additional features like pagination and filtering. Proper error handling and security measures are also implemented to ensure the API is robust and secure.