Todo-API is a RESTful API built with Node.js and Express.js. This project allows you to perform CRUD (Create, Read, Update, Delete) operations using a MongoDB database and provides API documentation through Swagger. You can add, list, update, and delete todos, with advanced validation to ensure data integrity.
- Add, list, update, and delete todos
- Advanced data validation
- Swagger-based API documentation (
/api-docs) - Modular and organized project structure
- Reliability through automated tests
- Node.js – Server-side JavaScript runtime
- Express.js – Web framework
- MongoDB – NoSQL database
- uuid – Unique ID generation
- dotenv – Environment variable management
- swagger-ui-express – API documentation interface
- Jest – For testing (or another test framework of your choice)
-
Clone the repository and navigate into the project folder:
git clone <repository-url> cd <repository-folder> npm install
-
Create a
.envfile and add the required environment variables:PORT=3000 MONGODB_URI=<your-mongodb-uri>
-
Start the server:
node server.js
-
Access the API documentation at:
http://localhost:3000/api-docs
The main directory contains app.js, server.js, and package.json. Additionally, it includes config, controllers, middlewares, models, routes, swagger, tests, and validations folders:
config/: Environment and database configurationscontrollers/: Business logicmiddlewares/: Middleware functionsmodels/: Data modelsroutes/: API endpointsswagger/: Swagger documentationtests/: Test filesvalidations/: Validation schemas
| Method | Endpoint | Description |
|---|---|---|
| GET | /todos |
Retrieve all todos |
| POST | /todos |
Create a new todo |
| GET | /todos/:id |
Retrieve a specific todo |
| PUT | /todos/:id |
Update a todo |
| DELETE | /todos/:id |
Delete a todo |
For detailed information and example requests, use the Swagger interface.
Basic CRUD operations are tested using Jest. Run the tests with:
npm test