A RESTful API built with Nest.js and MongoDB that provides comprehensive Pokémon information. This application includes full CRUD operations, pagination, data validation, and a seeding system to populate the database.
- Features
- Tech Stack
- Prerequisites
- Installation
- Database Configuration
- Running the Application
- API Endpoints
- Project Structure
- Environment Variables
- Available Scripts
- Testing
- ✅ Complete RESTful API with CRUD operations
- ✅ Data validation with class-validator
- ✅ Integrated pagination
- ✅ MongoDB database with Mongoose
- ✅ Docker Compose for local development
- ✅ Seeding system to populate initial data
- ✅ Global validation pipelines
- ✅ Static files served from
/public - ✅ TypeScript for type safety
- ✅ Modular structure following Nest.js best practices
- Framework: Nest.js v9
- Runtime: Node.js 18.x
- Package Manager: pnpm 7.x
- Database: MongoDB 5
- ODM: Mongoose
- Validation: class-validator & class-transformer
- Containerization: Docker & Docker Compose
- Language: TypeScript
- Testing: Jest
Before running this project, make sure you have installed:
- Node.js 18.x (recommended to use with Volta)
- pnpm 7.x
- Docker and Docker Compose
- Git
This project uses Volta for Node.js and pnpm version management:
# Install Volta (if you don't have it)
curl https://get.volta.sh | bash
# Versions will be configured automatically when cloning the project-
Clone the repository
git clone <repository-url> cd nest-pokedex
-
Install dependencies
pnpm install
-
Install Nest CLI globally (optional but recommended)
npm i -g @nestjs/cli
# Start MongoDB container in the background
docker-compose up -d
# Verify that the container is running
docker psThe database will be available at:
- Host:
localhost - Port:
27017 - Name:
nest-pokemon
Once the application is running, you can populate the database with initial data:
# Execute the seed via HTTP request
curl http://localhost:3000/api/v2/seedOr visit in your browser: http://localhost:3000/api/v2/seed
# Development with automatic reload
pnpm run start:dev
# Development with debug
pnpm run start:debug# Build the application
pnpm run build
# Run in production
pnpm run start:prodThe application will be available at: http://localhost:3000
http://localhost:3000/api/v2
| Method | Endpoint | Description | Parameters |
|---|---|---|---|
GET |
/pokemon |
Get all Pokémon | ?limit=10&offset=0 |
GET |
/pokemon/:term |
Get Pokémon by ID, name or number | - |
POST |
/pokemon |
Create a new Pokémon | Body: CreatePokemonDto |
PATCH |
/pokemon/:term |
Update Pokémon | Body: UpdatePokemonDto |
DELETE |
/pokemon/:id |
Delete Pokémon | - |
| Method | Endpoint | Description |
|---|---|---|
GET |
/seed |
Populate database with initial data |
curl "http://localhost:3000/api/v2/pokemon?limit=20&offset=0"# By name
curl "http://localhost:3000/api/v2/pokemon/pikachu"
# By number
curl "http://localhost:3000/api/v2/pokemon/25"
# By MongoDB ID
curl "http://localhost:3000/api/v2/pokemon/64a5f8b2c1234567890abcde"curl -X POST "http://localhost:3000/api/v2/pokemon" \
-H "Content-Type: application/json" \
-d '{
"name": "mew",
"no": 151
}'curl -X PATCH "http://localhost:3000/api/v2/pokemon/mew" \
-H "Content-Type: application/json" \
-d '{
"name": "mew-updated"
}'nest-pokedex/
├── 📁 public/ # Static files
│ ├── index.html
│ └── css/styles.css
├── 📁 src/
│ ├── 📁 common/ # Common module (pipes, DTOs, adapters)
│ │ ├── 📁 adapters/ # HTTP adapters
│ │ ├── 📁 dto/ # Shared DTOs (pagination)
│ │ ├── 📁 interfaces/ # Shared interfaces
│ │ └── 📁 pipes/ # Custom pipes
│ ├── 📁 pokemon/ # Main Pokémon module
│ │ ├── 📁 dto/ # Pokémon-specific DTOs
│ │ ├── 📁 entities/ # MongoDB schemas
│ │ ├── pokemon.controller.ts
│ │ ├── pokemon.service.ts
│ │ └── pokemon.module.ts
│ ├── 📁 seed/ # Seeding module
│ │ ├── 📁 interfaces/ # External data interfaces
│ │ ├── seed.controller.ts
│ │ ├── seed.service.ts
│ │ └── seed.module.ts
│ ├── app.module.ts # Root module
│ └── main.ts # Entry point
├── 📁 test/ # E2E tests
├── docker-compose.yaml # MongoDB configuration
├── package.json
└── README.md
Currently, the application uses hardcoded configuration. For production, consider using environment variables:
# .env (create file if needed)
DATABASE_URL=mongodb://localhost:27017/nest-pokemon
PORT=3000# Development
pnpm run start # Start application
pnpm run start:dev # Development with watch mode
pnpm run start:debug # Development with debug
# Build
pnpm run build # Build for production
pnpm run start:prod # Run production version
# Code quality
pnpm run format # Format code with Prettier
pnpm run lint # Run ESLint
# Testing
pnpm run test # Run unit tests
pnpm run test:watch # Tests in watch mode
pnpm run test:cov # Tests with coverage
pnpm run test:e2e # End-to-end tests# Unit tests
pnpm run test
# Tests with coverage
pnpm run test:cov
# E2E tests
pnpm run test:e2e
# Tests in watch mode
pnpm run test:watch- Fork the project
- 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
This project is unlicensed.
Built with ❤️ using Nest.js