Here's the README.md
content in Markdown format for your project. You can copy and paste this into a README.md
file:
# Task Management API
This is a RESTful API for managing users and tasks. It is built with Express.js and provides various endpoints for user and task management.
## Table of Contents
1. [Setup](#setup)
2. [Environment Variables](#environment-variables)
3. [API Endpoints](#api-endpoints)
- [User Endpoints](#user-endpoints)
- [Task Endpoints](#task-endpoints)
4. [Error Handling](#error-handling)
5. [Middleware](#middleware)
6. [License](#license)
## Setup
1. **Clone the repository:**
```bash
git clone <repository-url>
cd <repository-directory>
-
Install dependencies:
npm install
-
Set up environment variables: (See Environment Variables)
-
Start the server:
npm start
Create a .env
file in the root directory with the following environment variables:
PORT
: The port number on which the server runs.FRONTEND_URL
: The URL of the frontend application for CORS configuration.
Example:
PORT=5000
FRONTEND_URL=http://localhost:3000
-
Get All Users
- URL:
/user/all
- Method:
GET
- Description: Retrieve a list of all users.
- Response: JSON array of users.
- URL:
-
Get Current User
- URL:
/user/me
- Method:
GET
- Description: Retrieve the current authenticated user's information.
- Middleware:
isAuthenticated
- Response: JSON object of the user's details.
- URL:
-
Get User by ID
- URL:
/user/:id
- Method:
GET
- Description: Retrieve user information by user ID.
- Parameters:
id
(String) - User ID - Response: JSON object of the user's details.
- URL:
-
Create User
- URL:
/user/create
- Method:
POST
- Description: Create a new user.
- Body Parameters:
name
(String) - User's nameemail
(String) - User's emailpassword
(String) - User's password
- Response: JSON object of the created user.
- URL:
-
Login User
- URL:
/user/login
- Method:
POST
- Description: Login a user.
- Body Parameters:
email
(String) - User's emailpassword
(String) - User's password
- Response: JSON object containing authentication token.
- URL:
-
Logout User
- URL:
/user/logout
- Method:
POST
- Description: Logout the current user.
- Response: JSON message confirming logout.
- URL:
-
Delete User
- URL:
/user/:id
- Method:
DELETE
- Description: Delete a user by ID.
- Parameters:
id
(String) - User ID - Response: JSON message confirming deletion.
- URL:
-
Update User
- URL:
/user/:id
- Method:
PATCH
- Description: Update user details by ID.
- Parameters:
id
(String) - User ID - Body Parameters:
name
(String) - (Optional) New nameemail
(String) - (Optional) New email
- Response: JSON object of the updated user.
- URL:
-
Get All Tasks
- URL:
/task/all
- Method:
GET
- Description: Retrieve a list of all tasks.
- Response: JSON array of tasks.
- URL:
-
Create Task
- URL:
/task/create
- Method:
POST
- Description: Create a new task.
- Middleware:
isAuthenticated
- Body Parameters:
title
(String) - Task titledescription
(String) - Task descriptiondueDate
(Date) - Due date of the task
- Response: JSON object of the created task.
- URL:
-
Get My Tasks
- URL:
/task/mytask
- Method:
GET
- Description: Retrieve tasks associated with the authenticated user.
- Middleware:
isAuthenticated
- Response: JSON array of user's tasks.
- URL:
-
Get Task by ID
- URL:
/task/:id
- Method:
GET
- Description: Retrieve task details by task ID.
- Parameters:
id
(String) - Task ID - Response: JSON object of the task details.
- URL:
-
Update Task
- URL:
/task/:id
- Method:
PUT
- Description: Update task details by ID.
- Middleware:
isAuthenticated
- Parameters:
id
(String) - Task ID - Body Parameters:
title
(String) - (Optional) New titledescription
(String) - (Optional) New descriptiondueDate
(Date) - (Optional) New due date
- Response: JSON object of the updated task.
- URL:
-
Mark Task as Completed
- URL:
/task/complete/:id
- Method:
PUT
- Description: Mark a task as completed.
- Middleware:
isAuthenticated
- Parameters:
id
(String) - Task ID - Response: JSON object of the updated task.
- URL:
-
Delete Task
- URL:
/task/:id
- Method:
DELETE
- Description: Delete a task by ID.
- Middleware:
isAuthenticated
- Parameters:
id
(String) - Task ID - Response: JSON message confirming deletion.
- URL:
The API uses a custom error handling middleware to handle errors consistently. Errors are returned with a JSON response containing a message and an appropriate HTTP status code.
-
isAuthenticated: This middleware checks if the user is authenticated before allowing access to certain routes.
-
errorMiddleware: This middleware handles errors and sends a consistent JSON response.
This project is licensed under the MIT License - see the LICENSE file for details.
"dev": "NODE_ENV=Development nodemon index.js"
This is the API URL for authenticated todos with token, cookies and all!
https://authenticated-todos-backend.onrender.com