Skip to content

peyush-nuwal/todo-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 Todo API – Node.js + Express + MongoDB

A simple, secure Todo API with authentication and full CRUD support.

📦 Features

  • 🔐 User Authentication – Register and log in with secure JWT-based auth
  • 🛡️ Protected API Routes – Access control for authenticated users only
  • ✏️ Full Todo CRUD – Create, Read, Update, and Delete todos seamlessly
  • 🗃️ MongoDB + Mongoose – Schema-based data modeling
  • 🛠️ Robust Validation & Error Handling – Clean error responses and field checks

🛠️ Tech Stack

Backend:

🚀 Getting Started

✅ Prerequisites

🚀 Installation

Follow these steps to get started with this template:

1. Clone the repository

git clone https://github.com/peyush-nuwal/todo-api.git

2. Navigate to the project directory

cd todo-api

3. Install dependencies

npm install

Or use yarn or pnpm if you prefer.

4. Create a .env file and add the following:

PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_super_secret_key

5. Start the server in development mode

npm run dev

The API will be running at: http://localhost:5000/api

📡 API Endpoints

All routes are prefixed with: http://localhost:5000/api

🔐 Auth Routes

Method Endpoint Description
POST /register Register new user
POST /login Login and get JWT

Request Body for /register and /login:

{
  "email": "user@example.com",
  "password": "yourpassword"
}

📝 Todo Routes (Protected – Requires JWT)

Method Endpoint Description
GET /todos/ Get all todos for user
POST /todos/ Create a new todo
PUT /todos/:id Update a todo by ID
DELETE /todos/:id Delete a todo by ID

Example Todo Payload::

{
  "title": "Buy groceries",
  "description": "Milk, eggs, bread",
  "status": "pending"
}

🔒 For protected routes, include the token in the Authorization header as:
Bearer your_jwt_token_here


📁 Folder Structure

todo-api/
├── config/               # DB connection config
│   └── db.js
│
├── controllers/          # Route logic handlers
│   └── authController.js
│   └── todoController.js
│
├── middlewares/          # Custom middleware (auth, error handling)
│   └── authMiddleware.js
│   
│
├── models/               # Mongoose schemas
│   └── userSchema.js
│   └── todoSchema.js
│
├── routes/               # API route definitions
│   └── authRoutes.js
│   └── todoRoutes.js
│
│
├── .env                  # Environment variables
├── .gitignore
├── package.json
├── index.js             # Entry point

🔗 Connect with Me

📬 Contact

Feel free to connect or reach out for collaboration, feedback, or just to say hi!

About

A simple, secure Todo API with authentication and full CRUD support.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published