RESTful API to manage tasks and users, built with Node.js, Express, and MongoDB.
Ideal for learning or integrating into a simple task management system.
- Features
- Tech Stack
- Prerequisites
- Installation
- Usage
- API Endpoints
- Testing
- Project Structure
- Environment Variables
- Scripts
- Docker
- Contributing
- License
- Complete CRUD operations for Tasks and People
- RESTful architecture with proper HTTP methods
- Environment-based configuration with .env support
- Clean modular structure organized in
src/directory - MongoDB integration with Mongoose ODM
- Comprehensive testing suite with Jest and Supertest (68 tests)
- Input validation with custom middleware
- Error handling with global middleware
- Soft delete for tasks (preserves data)
- Hard delete for people
- Docker support for easy database setup
- Backend: Node.js + Express.js
- Database: MongoDB with Mongoose ODM
- Testing: Jest + Supertest
- Environment: dotenv
- Containerization: Docker & Docker Compose
- Validation: Custom validation middleware
- Development: Nodemon for hot reload
- Node.js
v18+ - MongoDB (local or MongoDB Atlas)
- Docker (optional, for easy database setup)
- Git for version control
git clone https://github.com/ENER90/tareas-api.git
cd tareas-apinpm installcp .env.template .envEdit the .env file with your configuration (see Environment Variables)
docker-compose up -d mongodb# Development mode
npm run dev
# Production mode
npm startOnce the server is running, you can access the API at:
- Local:
http://localhost:3000 - Health check: The server will log "App listening on port 3000" when ready
| Method | Endpoint | Description | Body |
|---|---|---|---|
GET |
/people |
Get all people | - |
GET |
/people/:id |
Get person by ID | - |
POST |
/people |
Create new person | { name, age } |
PUT |
/people/:id |
Update person | { name?, age? } |
DELETE |
/people/:id |
Delete person (hard delete) | - |
| Method | Endpoint | Description | Body |
|---|---|---|---|
GET |
/tasks |
Get all tasks | - |
GET |
/tasks/:id |
Get task by ID | - |
POST |
/tasks |
Create new task | { title, status, assignedTo, description?, dueDate? } |
PUT |
/tasks/:id |
Update task | { title?, status?, assignedTo?, description?, dueDate? } |
DELETE |
/tasks/:id |
Delete task (soft delete) | - |
POST /people
Content-Type: application/json
{
"name": "John Doe",
"age": 30
}POST /tasks
Content-Type: application/json
{
"title": "Complete project documentation",
"description": "Write comprehensive API documentation",
"status": "To Do",
"assignedTo": "64a7b8c9d1e2f3g4h5i6j7k8",
"dueDate": "2024-12-31T23:59:59.000Z"
}"To Do""In Progress""In Revision""Done"
This project includes a comprehensive testing suite with 68 tests covering all endpoints.
# Run all tests
npm test
# Run specific test file
npm test -- tests/routes/person.test.js
npm test -- tests/routes/task.test.js
# Run tests in watch mode
npm test -- --watch- β Person Routes: 25 tests (GET, POST, PUT, DELETE)
- β Task Routes: 43 tests (POST, GET, PUT, DELETE)
- β Validation Tests: All edge cases covered
- β Error Handling: Database and validation errors
- β Integration Tests: Full request/response cycle
tests/
βββ routes/
βββ person.test.js # Person endpoint tests
βββ task.test.js # Task endpoint tests
tareas-api/
βββ src/ # Source code directory
β βββ models/ # Mongoose models
β β βββ person.js # Person model
β β βββ task.js # Task model
β βββ routes/ # Express routes
β β βββ person.js # Person routes
β β βββ task.js # Task routes
β βββ validations/ # Input validation middleware
β β βββ person.js # Person validation
β β βββ task.js # Task validation
β βββ db.js # Database connection
βββ tests/ # Test files
β βββ routes/ # Route tests
β βββ person.test.js # Person tests (25 tests)
β βββ task.test.js # Task tests (43 tests)
βββ app.js # Express app configuration
βββ package.json # Dependencies and scripts
βββ jest.config.js # Jest configuration
βββ docker-compose.yml # Docker configuration
βββ .env.template # Environment variables template
βββ .env # Environment variables (create from template)
βββ README.md # This file
Create a .env file from .env.template and configure:
# Server configuration
PORT=3000
# Database configuration
MONGO_DB_URL="mongodb://user:password@localhost:27017/tasksdb"
# For MongoDB Atlas (cloud):
# MONGO_DB_URL="mongodb+srv://username:password@cluster.mongodb.net/tasksdb"PORT: Server port (default: 3000)MONGO_DB_URL: MongoDB connection string
{
"start": "node app.js",
"dev": "nodemon app.js",
"test": "jest --detectOpenHandles",
"test:watch": "jest --detectOpenHandles --watch"
}npm start: Run in production modenpm run dev: Run in development mode with auto-reloadnpm test: Run test suitenpm run test:watch: Run tests in watch mode
# Start MongoDB container
docker-compose up -d mongodb
# Stop MongoDB container
docker-compose downThe project includes a docker-compose.yml with:
- MongoDB container
- Persistent data volume
- Pre-configured authentication
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code structure in
src/ - Add tests for new features
- Ensure all tests pass before submitting (
npm test) - Use meaningful commit messages
- Follow the established validation patterns
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Express.js and MongoDB
- Comprehensive testing with Jest and Supertest
- Docker support for easy development
- Clean architecture following best practices
- Modular structure with separation of concerns