A RESTful API for task management built with Node.js, Express, and MySQL. Features include user authentication, CRUD operations, task filtering, and comprehensive error handling.
- User authentication with JWT
- Complete CRUD operations for tasks
- Task filtering by status, priority, and date
- Pagination and sorting
- Input validation and error handling
- MySQL database with proper relationships
- API documentation with Swagger
- Environment-based configuration
- Runtime: Node.js
- Framework: Express.js
- Database: MySQL
- Authentication: JWT (JSON Web Tokens)
- Validation: express-validator
- Documentation: Swagger/OpenAPI
- Node.js >= 14.x
- MySQL >= 8.0
- npm or yarn
# Clone the repository
git clone https://github.com/simonbrizuela/task-management-api.git
cd task-management-api
# Install dependencies
npm install
# Configure environment variables
cp .env.example .env
# Edit .env with your database credentials
# Run database migrations
npm run migrate
# Start the server
npm startPORT=3000
DB_HOST=localhost
DB_USER=your_user
DB_PASSWORD=your_password
DB_NAME=task_manager
JWT_SECRET=your_secret_key
JWT_EXPIRES_IN=24h
NODE_ENV=developmentPOST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/profile- Get user profile (protected)
GET /api/tasks- Get all tasks (with filters)GET /api/tasks/:id- Get task by IDPOST /api/tasks- Create new taskPUT /api/tasks/:id- Update taskDELETE /api/tasks/:id- Delete taskPATCH /api/tasks/:id/status- Update task status
GET /api/tasks?status=pending&priority=high&page=1&limit=10&sort=createdAt&order=desc
Users
- id (PK)
- name
- email (unique)
- password (hashed)
- created_at
Tasks
- id (PK)
- user_id (FK)
- title
- description
- status (pending, in_progress, completed)
- priority (low, medium, high)
- due_date
- created_at
- updated_atcurl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "securePassword123"
}'curl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"title": "Complete API documentation",
"description": "Write comprehensive API docs",
"priority": "high",
"due_date": "2024-12-31"
}'task-management-api/
├── src/
│ ├── config/
│ │ ├── database.js
│ │ └── swagger.js
│ ├── controllers/
│ │ ├── authController.js
│ │ └── taskController.js
│ ├── middleware/
│ │ ├── auth.js
│ │ ├── errorHandler.js
│ │ └── validator.js
│ ├── models/
│ │ ├── User.js
│ │ └── Task.js
│ ├── routes/
│ │ ├── auth.js
│ │ └── tasks.js
│ ├── utils/
│ │ ├── logger.js
│ │ └── helpers.js
│ └── app.js
├── migrations/
│ └── create_tables.sql
├── tests/
│ ├── auth.test.js
│ └── tasks.test.js
├── .env.example
├── .gitignore
├── package.json
└── README.md
npm testOnce the server is running, access the Swagger documentation at:
http://localhost:3000/api-docs
- Password hashing with bcrypt
- JWT-based authentication
- SQL injection prevention
- Rate limiting
- CORS configuration
- Input validation and sanitization
MIT License - See LICENSE file for details
Simon Brizuela
- GitHub: @simonbrizuela
- Email: simonbrizuela08@gmail.com
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.