E-Commerce Express Application with TypeScript and MongoDB
This is a backend server for an e-commerce product management system. It is built using TypeScript, Node.js, Express, Mongoose, and MongoDB. Validation is performed with Zod.
- Create Product: Use the api/products endpoint to create a new product.
- Get Product by ID: Use the api/products/:id endpoint to retrieve a product by its ID.
- Fetch all Products: Use the api/products endpoint to retrieve all products available.
- Delete Product by ID: Use the api/products/:id endpoint to delete a product by its ID.
- Search Products: Use the api/products?searchTerm=searchKeyword endpoint to search for products using a search term.
- Create Order: Use the api/orders endpoint to create a new product.
- Fetch all orders: Use the api/orders endpoint to retrieve all orders.
- Search order for a user: Use the api/orders?email=userEmail endpoint to search for products using a search term.
- ** Clone the repository:
git clone https://github.com/KaziMdMehediHasan/product-management
cd ecommerce-product-management
- ** Install dependencies:
npm install
- ** Environment Variables:
Create a .env file in the root directory of the project and add the following environment variables:
PORT=3000
MONGODB_URI=your_mongodb_connection_string
- ** Start the server:
npm run start:dev
The server will start on http://localhost:5000.
- Endpoint:
/api/products
-
Method: POST
-
Sample Request Body:
{
"name": "Samsung Galaxy S21",
"description": "High-performance Android smartphone with advanced camera capabilities.",
"price": 799,
"category": "Electronics",
"tags": ["smartphone", "Samsung", "Android"],
"variants": [
{
"type": "Color",
"value": "Phantom Black"
},
{
"type": "Storage Capacity",
"value": "128GB"
}
],
"inventory": {
"quantity": 29,
"inStock": true
}
}
- Endpoint:
/api/products/:id
- Method: GET
- Endpoint:
/api/products/:id
- Method: DELETE
- Endpoint:
/api/products?searchTerm=searchKeyword
- Method: GET
- Endpoint:
/api/orders
- Method: POST
- Sample Request Body:
{
"email": "[email protected]",
"productId": "664e1210c34873fba7ec0804",
"price": 299,
"quantity": 4
}
- Endpoint:
/api/orders?email=userEmail
- Method: GET