Todo List Project is all about Implimentation of RESTful API for managing a Todo list using MongoDB and Mongoose. Users can create, read, update, and delete Tasks OR Todo items. The API is built using Node.js, Express.js, MongoDB, and Mongoose. and used jsonwebtoken for authorization
- Setup
- Database Configuration
- API Endpoints
- Authentication
- Environment Variables
- Running the Project
- Testing
- License
-
Clone this repository:
git clone [<repository-url>]((https://github.com/KARTIK1111/Task-Manager.git))
-
Install dependencies:
npm install
-
Set up the necessary environment variables in a
.env
file (see Environment Variables). -
Run the API:
npm start
-
Access the API at
http://localhost:3000
.
-
Ensure you have a running MongoDB instance.
-
Set up environment variables in a
.env
file:PORT=API server port. (Default: 3000) MONGO_URL=your-mongodb-url SECRET_KEY=your-secret-key
...
Retrieve a list of all Todo items.
Response:
{
"status": true,
"message": "Task List",
"data": {
"_id": "64e0da07edd909260abf3146",
"title": "Go for a run",
"description": "Run for 30 minutes in the park",
"status": false,
"createdAt": "2023-08-19T15:04:39.554Z",
"updatedAt": "2023-08-19T15:04:39.554Z",
"__v": 0
}
}
``
[
// ... more todo items
]
Retrieve a specific Todo item by ID.
Parameters:
id
: Todo item ID
Response:
{
"status": true,
"message": "taskDetail:",
"data": {
"_id": "64e9e57df884c5f301480123",
"taskname": "to do 1",
"description": "1.sugar 2.oil 3.tea",
"taskstatus": "pending",
"createdAt": "2023-08-26T11:43:57.632Z",
"updatedAt": "2023-08-26T11:43:57.632Z",
"__v": 0
}
}
Create a new Todo item.
Request Body:
{
"taskname":"to do 1",
"description":"1.sugar 2.oil 3.tea 4.cookies"
}
Response:
{
"status": true,
"message": "Task Created",
"data": {
"taskname": "to do 1",
"description": "1.sugar 2.oil 3.tea 4.cookies",
"taskstatus": "pending",
"_id": "64e9f16237ee6885eae643cb",
"createdAt": "2023-08-26T12:34:42.390Z",
"updatedAt": "2023-08-26T12:34:42.390Z",
"__v": 0
}
}
Update an existing Todo item.
Parameters:
id
: Todo item ID
Request Body:
{
"description":"1.sugar 2.oil 3.tea 4.Chips"
}
Response:
{
"status": true,
"message": "Task updated",
"data": {
"_id": "64e9f14837ee6885eae643c9",
"taskname": "to do 1",
"description": "1.sugar 2.oil 3.tea 4.Chips",
"taskstatus": "pending",
"createdAt": "2023-08-26T12:34:16.739Z",
"updatedAt": "2023-08-26T12:43:13.219Z",
"__v": 0
}
}
Delete a Todo item.
Parameters:
id
: Todo item ID
Response:
{
"status": true,
"message": "task is deleted"
}
Register a new user.
Request Body:
{
"username":"robert",
"email":"[email protected]",
"password":"Robert@123"
}
Response:
{
"status": true,
"message": "user created",
"userdata": {
"username": "robert",
"email": "[email protected]",
"password": "$2b$10$94oSQzcRwWmWTW15wQcV3umIqjHp30t7krWYfmukc.Nq.xskb3di2",
"_id": "64e9f64859dce1582fe9b05a",
"createdAt": "2023-08-26T12:55:36.273Z",
"updatedAt": "2023-08-26T12:55:36.273Z",
"__v": 0
}
}
User login.
Request Body:
{
"email":"[email protected]",
"password":"Robert@123"
}
Response:
{
"staus": true,
"message": "User login Successfully"
}
This API requires authentication using JSON Web Tokens (JWT). Users need to register and log in to obtain a JWT token for accessing protected routes.
User passwords are securely hashed using the bcrypt library before being stored in the database. This adds an extra layer of security to protect user data.
Before running the project, you need to set up the following environment variables in a .env
file:
-
PORT
: The port on which the API server will listen. (Default: 3000) -
MongoDB
: MongoDB connection URL. -
SECRET_KEY
: Secret key used for generating and verifying JSON Web Tokens (JWT) for authentication.
Example .env
file:
PORT=3000
MongoDB=mongodb://localhost:27017/your-database-name
SECRET_KEY=my-secret-key
-
Run the API:
npm start
-
Access the API at
http://localhost:3000
.
To run tests, execute:
npm test