This API provides endpoints for managing products, orders, and user authentication in an e-commerce platform.
- Create Product
POST-http://localhost:3000/api/v1/products - Get All Products
GET-http://localhost:3000/api/v1/products - Get Product by ID
GET-http://localhost:3000/api/v1/products/{productId} - Update Product
PUT-http://localhost:3000/api/v1/products/{productId} - Delete Product
DELETE-http://localhost:3000/api/v1/products/{productId}
{
"_id": "6650ba7b8aca58d7ed510f9d",
"name": "Wireless Earbuds",
"description": "Compact and comfortable earbuds with noise cancellation and long battery life.",
"price": 79.99,
"category": "Electronics",
"tags": ["audio", "portable", "wireless", "earbuds"],
"variants": [
{
"type": "color",
"value": "Black"
},
{
"type": "color",
"value": "White"
}
],
"inventory": {
"quantity": 150,
"inStock": true
}
}- Create Order
POST-http://localhost:3000/api/v1/orders/create-order - Get All Orders by Email
GET-http://localhost:3000/api/v1/orders?email={userEmail}
{
"email": "groot@gmail.com",
"productId": "67c947f88220525dca10a060",
"quantity": 15,
"price": 5000
}- Register User
POST-http://localhost:3000/api/v1/users/register - Login User
POST-http://localhost:3000/api/v1/users/login
{
"email": "mrgroot@gmail.com",
"password": "1234",
"role": "admin"
}{
"email": "mrgroot@gmail.com",
"password": "1234"
}- TypeScript
- MongoDB
- PNPM
- bcryptjs - Used for hashing and verifying passwords securely.
- cors - Enables Cross-Origin Resource Sharing for handling requests from different domains.
- dotenv - Loads environment variables from a
.envfile. - express - A minimal and flexible Node.js web application framework.
- jsonwebtoken - Used for generating and verifying JSON Web Tokens (JWT) for authentication.
- mongoose - ODM (Object Data Modeling) library for MongoDB, providing schema-based models.
- zod - A TypeScript-first schema validation library for input validation.
PORT=3000
MONGODB="mongodb://localhost:27017/ecommerce-api"
JWT_SECRET="grootdevelopmentpvt"