REST API for managing e-commerce categories, products, and product images. Built with Express, Prisma, PostgreSQL, Cloudinary, and Swagger.
- Category creation and listing
- Product CRUD
- Product search and filtering by text, category, price range, and pagination
- Product image upload, replacement, and deletion via Cloudinary
- PostgreSQL persistence through Prisma
- Swagger API documentation
- Structured request logging with Pino
- Node.js with ES modules
- Express 5
- Prisma 7
- PostgreSQL
- Cloudinary
- Multer
- Swagger UI
- Pino
- Node.js
- pnpm
- PostgreSQL database
- Cloudinary account
pnpm installCreate a .env file in the project root:
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
PORT=3000
CLOUDINARY_CLOUD_NAME="your-cloud-name"
CLOUDINARY_API_KEY="your-api-key"
CLOUDINARY_API_SECRET="your-api-secret"
NODE_ENV="development"DATABASE_URL and the Cloudinary values are required.
Create PostgreSQL Database
# Connect to PostgreSQL
psql -U postgres
# Create the database
CREATE DATABASE e_commerce_db;
# Exit psql
\qRun migrations:
pnpm prisma migrate devSeed sample data:
pnpm seedDevelopment:
pnpm devProduction:
pnpm startThe API runs on http://localhost:3000 by default. Set PORT to use a different port.
Swagger UI is available at:
http://localhost:3000/api-docs
GET /- API statusGET /ping- service liveness check
GET /api/categories- list categoriesPOST /api/categories- create a category
GET /api/products- list productsGET /api/products/search- search and filter productsGET /api/products/:id- get a product by IDPOST /api/products- create a productPATCH /api/products/:id- update a productDELETE /api/products/:id- delete a product
POST /api/product/:id/image- upload or replace a product imageDELETE /api/product/:id/image- delete a product image
Create a category:
curl -X POST http://localhost:3000/api/categories \
-H "Content-Type: application/json" \
-d '{
"name": "Electronics",
"description": "Electronic devices and accessories",
"slug": "electronics"
}'Create a product:
curl -X POST http://localhost:3000/api/products \
-H "Content-Type: application/json" \
-d '{
"name": "Wireless Headphones",
"description": "Noise-canceling Bluetooth headphones",
"price": 78000,
"categoryId": 1,
"stockQuantity": 45
}'Search products:
curl "http://localhost:3000/api/products/search?search=headphones&page=1&limit=10"Upload a product image:
curl -X POST http://localhost:3000/api/product/1/image \
-F "image=@/path/to/image.jpg".
├── app.js
├── prisma/
│ ├── schema.prisma
│ ├── seed.js
│ └── migrations/
└── src/
├── config/
├── middleware/
├── modules/
│ ├── category/
│ ├── image_upload/
│ └── product/
└── utils/
pnpm dev- start the API with Nodemonpnpm start- start the API with Nodepnpm seed- seed the database with sample categories and productspnpm test- placeholder test command
Developed by: MUEGHE ABUEMKEZE CHU
Connect with me:
- 🐙 GitHub: @chu29
- 🐦 Twitter: @unku_chu
- 💼 LinkedIn: MUEGHE ABUEMKEZE CHU
- 📧 Email: chu.amk22@gmail.com