This is the accompanying code for the Blog article Building a Task Management API with NestJS, Prisma, and Docker.
A scalable and robust task management REST API built with NestJS, Prisma, Docker, and Swagger. This application allows users to create, manage, and organize tasks with features like priority levels, due dates, and status tracking.
- 🔐 JWT Authentication - Secure user registration and login
- 📝 Task Management - Full CRUD operations for tasks
- 🏷️ Task Organization - Categorization, labels, priorities, and statuses
- 📚 API Documentation - Interactive Swagger documentation
- 🐳 Containerization - Docker support for easy deployment
- 🔄 Database Migrations - Prisma migrations for version control of the database schema
- ✅ Data Validation - Request validation using class-validator
- 📊 TypeScript Support - Type-safe development experience
- Backend Framework: NestJS
- Database: PostgreSQL
- ORM: Prisma
- API Documentation: Swagger/OpenAPI
- Authentication: JWT (JSON Web Tokens)
- Containerization: Docker
- Validation: class-validator and class-transformer
Before you begin, ensure you have the following installed:
- Node.js (v18 or later)
- npm (v8 or later)
- Docker and Docker Compose (for containerized setup)
- PostgreSQL (if running without Docker)
-
Clone the repository
git clone https://github.com/jideabdqudus/task-manager-api.git cd task-manager-api -
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory with the following variables:# Database DATABASE_URL="postgresql://postgres:postgres@localhost:5432/tasksdb?schema=public" # JWT JWT_SECRET="your-secret-key" JWT_EXPIRES_IN="1d" # Server PORT=3000
-
Set up the database
# Generate Prisma client npx prisma generate # Run migrations npx prisma migrate dev # Seed the database (optional) npx prisma db seed
-
Start the development server
npm run start:dev
Once the application is running, you can access the Swagger documentation at:
http://localhost:3000/api-docs
This provides an interactive interface to explore and test all API endpoints.
├── prisma/ # Prisma schema and migrations
├── src/
│ ├── auth/ # Authentication module
│ ├── tasks/ # Task management module
│ ├── users/ # User management module
│ ├── database/ # Database module with Prisma service
│ ├── app.module.ts # Main application module
│ └── main.ts # Application entry point
├── test/ # End-to-end tests
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── .env # Environment variables
└── package.json # Project dependencies
Here are the main API endpoints:
POST /api/auth/register- Register a new userPOST /api/auth/login- Login and get JWT token
GET /api/tasks- Get all tasks for the authenticated userGET /api/tasks/:id- Get a specific taskPOST /api/tasks- Create a new taskPATCH /api/tasks/:id- Update a taskDELETE /api/tasks/:id- Delete a task
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com","password":"password123"}'curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"john@example.com","password":"password123"}'curl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{"title":"Complete NestJS project","description":"Finish the task management API","priority":"HIGH","dueDate":"2025-05-01T00:00:00.000Z"}'This project is licensed under the MIT License - see the LICENSE file for details.