A RESTful Todo API built with Express.js and MongoDB. Features CRUD operations for managing tasks with proper error handling and data persistence. Uses Mongoose ODM for MongoDB interactions and includes middleware for error handling and CORS support.
- Features
- Tech Stack
- Project Structure
- API Endpoints
- Getting Started
- Environment Variables
- API Documentation
- β¨ Complete CRUD operations for todo items
- π MongoDB integration using Mongoose
- π RESTful API endpoints
- β‘ Express middleware implementation
- π‘οΈ Error handling and validation
- π CORS enabled
- Node.js
- Express.js
- MongoDB
- Mongoose
- CORS
- dotenv
todo-list-api/
βββ src/
β βββ controllers/
β β βββ todo.controller.js
β βββ models/
β β βββ todo.model.js
β βββ routes/
β β βββ todo.routes.js
β βββ index.js
βββ .env
βββ .gitignore
βββ package.json
Method | Endpoint | Description |
---|---|---|
GET | /api/todos | Get all todos |
GET | /api/todos/:id | Get a specific todo |
POST | /api/todos | Create a new todo |
PUT | /api/todos/:id | Update a todo |
DELETE | /api/todos/:id | Delete a todo |
-
Clone the repository bash
git clone https://github.com/SuchitArtal/todo-list-api.git
cd todo-list-api
-
Install dependencies bash
npm install
-
Set up environment variables Create a
.env
file in the root directory and add:
env PORT=3000 MONGODB_URI=mongodb://localhost:27017/todo-api
-
Start MongoDB Make sure MongoDB is running on your system
-
Run the application bash
npm start
-
Development
npm run dev
-
Production
npm start
{
"_id": "string",
"title": "string",
"description": "string",
"completed": "boolean",
"createdAt": "date"
}
- 200: Operation successful
- 201: Resource created
- 204: Resource deleted
- 400: Bad Request
- 404: Resource not found
- 500: Internal server error
The API returns error responses in the following format:
{
"message": "Error message description"
}
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
ISC