https://github.com/yuvrajnode/todo-backend-with-database
A secure Node.js API for user authentication and todo management using Express, MongoDB, and JWT.
https://github.com/yuvrajnode/todo-backend-with-database
express jwt-authentication mongodb nodejs
Last synced: about 1 month ago
JSON representation
A secure Node.js API for user authentication and todo management using Express, MongoDB, and JWT.
- Host: GitHub
- URL: https://github.com/yuvrajnode/todo-backend-with-database
- Owner: yuvrajnode
- Created: 2025-07-06T04:10:13.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-09T18:13:26.000Z (12 months ago)
- Last Synced: 2025-10-25T03:03:00.114Z (8 months ago)
- Topics: express, jwt-authentication, mongodb, nodejs
- Language: JavaScript
- Homepage:
- Size: 4.01 MB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ง Auth Todo API
A simple RESTful backend API built with **Node.js**, **Express**, **MongoDB**, and **JWT** that allows users to register, log in, and manage their personal todo tasks.
---
## ๐ Features
- โ
User Signup and Login
- ๐ JWT-based Authentication using custom `token` header
- ๐ Create, fetch, update, and delete todos
- ๐๏ธ MongoDB with Mongoose schemas & models
- ๐ฆ Clean JSON-based REST API
---
## ๐ Project Structure
```
โโโ index.js # Main server file (routes, middleware, logic)
โโโ db.js # MongoDB schemas and models
โโโ package.json # Project metadata and dependencies
โโโ .gitignore # Files to ignore in version control
```
---
## ๐ ๏ธ Tech Stack
- **Node.js**
- **Express.js**
- **MongoDB** with **Mongoose**
- **JWT** for authentication
- **bcrypt** for password hashing
- **zod** for request validation
---
## ๐งช API Endpoints
### ๐น POST `/signup`
Registers a new user.
**Request Body:**
```json
{
"email": "user@example.com",
"password": "yourpassword",
"name": "Yuvraj"
}
```
**Response:**
```json
{
"message": "You are signed up"
}
```
---
### ๐น POST `/signin`
Authenticates the user and returns a JWT token.
**Request Body:**
```json
{
"email": "user@example.com",
"password": "yourpassword"
}
```
**Response:**
```json
{
"token": "JWT_TOKEN_HERE"
}
```
---
### ๐น POST `/todo`
Creates a new todo.
**Headers:**
```
token: JWT_TOKEN_HERE
```
**Request Body:**
```json
{
"title": "Learn Node.js"
}
```
**Response:**
```json
{
"message": "Todo created"
}
```
---
### ๐น POST `/todos`
Fetches all todos of the authenticated user.
**Headers:**
```
token: JWT_TOKEN_HERE
```
**Response:**
```json
{
"todos": [
{
"_id": "todoId",
"title": "Learn Node.js",
"done": false,
"userId": "userId"
}
]
}
```
---
### ๐น PUT `/todo/:id`
Updates a todo (e.g., mark as done).
**Headers:**
```
token: JWT_TOKEN_HERE
```
**Request Body:**
```json
{
"done": true
}
```
**Response:**
```json
{
"message": "Todo updated"
}
```
---
### ๐น DELETE `/todo/:id`
Deletes a todo.
**Headers:**
```
token: JWT_TOKEN_HERE
```
**Response:**
```json
{
"message": "Todo deleted"
}
```
---
## โ๏ธ Setup Instructions
1. **Clone the repository:**
```bash
git clone https://github.com/yuvrajnode/todo-backend-with-database.git
cd todo-backend-with-database
```
2. **Install dependencies:**
```bash
npm install
```
3. **Configure MongoDB URI and secret (optional):**
If using environment variables, create a `.env` file and add:
```
MONGO_URI=your_mongo_connection_string
JWT_SECRET=your_secret
```
(Or keep them hardcoded in `index.js` as done currently.)
4. **Start the server:**
```bash
node index.js
```
Server will run at:
๐ `http://localhost:3000`
---
## ๐โโ๏ธ Author
Made with โค๏ธ by **Yuvraj Singh**
GitHub: [@yuvrajnode](https://github.com/yuvrajnode)
---
## ๐ License
This project is open source and free to use under the [MIT License](LICENSE).