This is a simple and secure To-Do List API built with Node.js, Express.js, MongoDB, and JWT authentication. It allows users to register, log in, and perform full CRUD operations (Create, Read, Update, Delete) on their to-do tasks.
- π User registration and login with JWT authentication
- π‘οΈ Protected routes using middleware
- π Create personal to-do tasks
- π Retrieve all tasks of a user
- π§Ύ Update existing tasks
- β Delete tasks by ID
- Node.js β JavaScript runtime
- Express.js β Web framework
- MongoDB β NoSQL database
- Mongoose β ODM for MongoDB
- JWT β JSON Web Token for authentication
. βββ db/ β βββ config.js # MongoDB connection β βββ User.js # User schema β βββ Todo.js # Todo schema βββ index.js # Main API entry point
-
Clone the repository:
git clone https://github.com/your-username/todo-api.git cd todo-api -
Install dependencies:
npm install
-
Start MongoDB locally (or configure Atlas URI in db/config.js).
-
Run the server:
node index.js
-
The server runs on http://localhost:5000
All to-do routes are protected. Users must log in and pass the JWT token in the request header. ```bash auth: Bearer
| Method | Route | Description |
|---|---|---|
| POST | /register |
Register new user |
| POST | /login |
Login and get token |
| Method | Route | Description |
|---|---|---|
| POST | /create |
Create new to-do |
| GET | /todos/:author |
Get all to-dos for a user |
| PUT | /update/:id |
Update to-do by ID |
| DELETE | /delete/:id |
Delete to-do by ID |
{
"email": "user@example.com",
"password": "123456"
}
{
"name": "Buy groceries",
"author": "user@example.com"
}
This project is licensed for educational use. Contributions are welcome.
Made with π» by Ranadeb Saha
Let me know if you want this merged into your full README.md or need additional sections like DB schema or setup instructions.