A NestJS microservice for managing products in our e-commerce platform.
- Node.js (v18 or higher)
- Docker and Docker Compose
- Yarn
-
Clone the repository
git clone <repository-url> cd e-commerce/packages/product-service -
Set up environment variables Copy the example env file
cp .env.example .envThe .env file should contain:
DATABASE_URL="mongodb://localhost:27017/products?replicaSet=rs0&directConnection=true" -
Start MongoDB with Docker
docker compose up -d -
Run the application
yarn start -
Install dependencies
yarn install -
Generate Prisma client
yarn prisma generate -
Start the development server
yarn start:dev
The service runs on http://localhost:3000 with the following endpoints:
POST /api/products- Create a productGET /api/products- List all productsGET /api/products/:id- Get a single productPUT /api/products/:id- Update a productDELETE /api/products/:id- Delete a product
Documentation is available at http://localhost:3000/api/docs
Create a product
curl -X POST http://localhost:3000/api/products \
-H "Content-Type: application/json" \
-d '{
"name": "Test Product",
"description": "A test product",
"price": 29.99,
"sku": "TEST-001",
"stock": 100
}'
yarn start:dev- Start with hot-reloadyarn start:debug- Start with debuggingyarn test- Run testsyarn lint- Run linting
-
MongoDB Connection Issues
- Ensure Docker is running
- Try restarting the containers:
docker-compose down -v && docker-compose up -d - Check MongoDB logs:
docker-compose logs mongodb
-
Prisma Issues
- Regenerate Prisma client:
yarn prisma:generate - Reset database:
yarn prisma:reset
- Regenerate Prisma client:
- Create a feature branch
- Make your changes
- Submit a pull request
MIT