A RESTful API for managing todo items built with Node.js, Express, TypeScript, and MongoDB.
- ✅ Create, Read, Update, Delete (CRUD) operations
- ✅ Auto-incrementing serial numbers
- ✅ Status management (pending, in-progress, completed)
- ✅ TypeScript for type safety
- ✅ MongoDB with Mongoose ODM
- ✅ Error handling with http-errors
- ✅ Input validation
The server will start on http://localhost:3000
todo-api/
├── config/
│ ├── config.ts
│ └── db.ts
├── src/
│ ├── todo
│ │ ├── controller.ts # Business logic
│ │ ├── routes.ts # API routes
│ │ ├── model.ts # MongoDB schema
│ │ └── types.ts # TypeScript interfaces
│ └── app.ts
│
├── .env # Environment variables
├── .gitignore
├── package.json
├── eslint.config.mjs
├── tsconfig.json
├── server.ts # Express app setup
└── README.md
http://localhost:3000/api
| Method | Endpoint | Description |
|---|---|---|
| POST | /todos |
Create a new todo |
| GET | /todos |
Get all todos |
| GET | /todos/:id |
Get a single todo by ID |
| PUT | /todos/:id |
Update a todo |
| DELETE | /todos/:id |
Delete a todo |
{
sno: number, // Auto-incrementing serial number
title: string, // Required
description?: string, // Optional
status: 'pending' | 'in-progress' | 'completed',
createdAt: Date, // Auto-generated
updatedAt: Date // Auto-generated
}- Set base URL:
http://localhost:3000/api - Test endpoints in this order:
- Create a todo
- Get all todos
- Get single todo
- Update todo
- Delete todo
{
"express": "^4.18.2",
"mongoose": "^8.0.0",
"http-errors": "^2.0.0",
"dotenv": "^16.3.1"
}Shreeja Vyas
- GitHub: shreeja5714
Happy Coding! 🚀