The purpose of this project is to create a backend API for managing users and products. It includes functionalities such as user registration, login, logout, product creation, and fetching all products.
-
User Management:
- User Registration: Allows users to register by providing necessary information.
- User Login: Enables registered users to authenticate and access their account.
- User Logout: Provides functionality for users to log out securely.
-
Product Management:
- Product Creation: Allows authenticated users to create new products with details like name, price, description, and image.
- Get All Products: Retrieves all products from the database.
- TypeScript
- Express.js
- MongoDB
- jsonwebtoken
To run the project locally, follow these steps:
- Clone the repository:
git clone [email protected]:KodaKodama/backendAssignment.git
- Navigate to the project directory:
cd backendAssignment
- Install dependencies:
npm install
- Set up MongoDB Atlas:
- Create a MongoDB Atlas account if you don't have one already.
- Set up a cluster and database.
- Obtain your connection string.
- Create a .env file in the project root and add the following:
Replace your-mongodb-connection-string with your MongoDB Atlas connection string.
CONNECTION_STRING=your-mongodb-connection-string
Compile TypeScript files to JavaScript using the TypeScript compiler.
npm run build
Start the server on port 1335.
npm start
Access the server at http://localhost:1335.
- Endpoint:
/user/register
- Method:
POST
- Description: Registers a new user.
- Request Body:
{
"name": "User Name",
"email": "[email protected]",
"password": "Password@123"
}
Response: Returns a success message upon successful registration.
- Endpoint:
/user/login
- Method:
POST
- Description: Login a new user.
- Request Body:
{
"email": "[email protected]",
"password": "Password@123"
}
Response: Returns a JWT token upon successful login.
- Endpoint:
/user/logout
- Method:
GET
- Description: Logout user.
- Endpoint:
/user/edit
- Method:
PUT
- Description: Updates the profile information for an existing user.
- Request Body:
{
"name": "New Name",
"email": "[email protected]",
"password": "newPassword@123"
}
Response: Returns a success message upon successful update.
- Endpoint:
/product/create
- Method:
POST
- Description: create a product for seller.
- Request Body:
{
"name": "Product Name",
"price": 999,
"description": "Product description",
"image": "product-image.jpg"
}
Response: Returns a success message upon successful product creation.
- Endpoint:
/product/get/all
- Method:
GET
- Description: Retrieves all products from the database.
- Response: Returns an array of product objects..
This project is licensed under the MIT License.