2.2 KiB
Ecomm Backend
This repository contains the backend implementation for the Ecomm e-commerce application.
Description
This is a simple e-commerce backend application built with Node.js, TypeScript, Express.js, MongoDB, and Docker. It provides API endpoints to manage users, products and cart of user.
Table of Contents
- [Technologies Used]
- [How to Run]
- [API Documentation]
- [Users]
- [Create a New User]
- [Login]
- [Products]
- [Get All Products]
- [Users]
Technologies Used
- Node.js
- TypeScript
- Express.js
- MongoDB
- Mongoose ORM
- Docker (docker-compose)
- bcrypt
- JWT
How to Run
To run the Ecomm backend application, follow these steps:
- Clone the repository.
- Ensure that you have Docker and Docker Compose installed.
- Implement the required environment variables by creating an
.env
file. - Run the following command in the root directory:
docker-compose up ```
The application will be running on port 3000, and the database will be running on port 27017.
API Documentation
Users
Create a New User - POST /users Creates a new user.
Request Body
{
"name": "string",
"email": "string",
"password": "string"
}
Response Body status code 200
{
message:
"User created successfully"
}
status code 400
{
message:
"User already exists"
}
status code 500
{
message:
"Internal server error"
}
Login - POST /users/login Logs in a user.
Request Body
{
"email": "string",
"password": "string"
}
Response Body status code 200
{
access-token:
"TOKEN"
}
Products
Get All Products - GET /products Gets all products.
Parameters
page: number(default: 0)
limit: number(default: 50)
Response Body status code 200
{
products: [
{
_id: "string",
name: "string",
description: "string",
price: number,
image: "string",
createdAt: "string",
updatedAt: "string"
}
]
}
status code 404
{
message:
"Product not found."
}
Cart
Add Product to Cart - POST /cart Adds a product to cart. (authentication required)
Request Body
{
"productId": "string"
}
Response Body status code 200
{
Cart :{
"{ProductId}": Quantity
}
}