https://github.com/imoamo/1mg_backend
Tata 1mg_backend is a Node.js e-commerce backend using Express.js, MongoDB, and JWT for authentication, handling user management, cart functionality, and dynamic routing.
https://github.com/imoamo/1mg_backend
bcryptjs expressjs jwt-token mongodb moongose node-js
Last synced: about 2 months ago
JSON representation
Tata 1mg_backend is a Node.js e-commerce backend using Express.js, MongoDB, and JWT for authentication, handling user management, cart functionality, and dynamic routing.
- Host: GitHub
- URL: https://github.com/imoamo/1mg_backend
- Owner: imoamo
- Created: 2024-08-06T12:08:37.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-07T05:30:59.000Z (almost 2 years ago)
- Last Synced: 2025-05-30T16:27:14.866Z (about 1 year ago)
- Topics: bcryptjs, expressjs, jwt-token, mongodb, moongose, node-js
- Language: JavaScript
- Homepage: https://1-mg-clone.netlify.app/
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tata 1mg Backend
`Tata 1mg_backend` is a Node.js-based backend project that supports an e-commerce platform. It provides functionalities for user authentication, cart management, and dynamic routing. The backend is built using Express.js, with MongoDB as the database, and JWT for authentication.
## Technologies Used
- **Node.js**: JavaScript runtime
- **Express.js**: Web framework for Node.js
- **bcrypt**: Library for hashing passwords
- **JSON Web Token (JWT)**: For user authentication
- **MongoDB**: NoSQL database
- **Mongoose**: ODM for MongoDB
## Installation
1. Clone the repository:
```bash
git clone https://github.com/imoamo/1mg_backend.git
```
2. Navigate to the project directory:
```bash
cd 1mg_backend
```
3. Install the dependencies:
```bash
npm install
```
## API Endpoints
### Auth Routes
#### Signup
- **URL**: `/api/auth/signup`
- **Method**: POST
- **Description**: Creates a new user account.
- **Request Body**:
```json
{
"name": "string",
"email": "string",
"password": "string"
}
```
- **Response**:
```json
{
"message": "User created successfully",
"user": user
}
```
#### Login
- **URL**: `/api/user/login`
- **Method**: POST
- **Description**: Logs in a user and returns a JWT token.
- **Request Body**:
```json
{
"email": "string",
"password": "string"
}
```
- **Response**:
```json
{
"token": "JWT token"
}
```
### User Routes
#### Get User Profile
- **URL**: `/api/user/:id`
- **Method**: GET
- **Description**: Fetches user profile details.
- **Response**:
```json
{
"user": user
}
```
### Product Routes
#### Add to Cart
- **URL**: `/api/product/create`
- **Method**: POST
- **Description**: Adds a product to the user's cart.
- **Request Body**:
```json
{
"productId": "string",
"quantity": "number"
}
```
- **Response**:
```json
{
"message": "Product added to cart",
"cart": cart
}
```
#### Remove from Cart
- **URL**: `/api/Product/delete/:id`
- **Method**: DELETE
- **Description**: Removes a product from the user's cart.
- **Request Body**:
```json
{
"productId": "string"
}
```
- **Response**:
```json
{
"message": "Product removed from cart",
"cart": cart
}
```
#### Get Cart
- **URL**: `/api/product/`
- **Method**: GET
- **Description**: Fetches the user's cart.
- **Response**:
```json
{
"cart": cart
}
```
## Dynamic Routing
This backend supports dynamic routing based on user ID and other dynamic parameters, allowing personalized data retrieval.
## Middleware
- **Authentication Middleware**: Verifies JWT tokens and protects routes.
- **Error Handling Middleware**: Centralized error handling for the application.
## Error Handling
The application uses a global error handler to manage different types of errors, ensuring a consistent error response structure.
## Security
- **Password Hashing**: User passwords are hashed using bcrypt.
- **JWT**: JSON Web Tokens are used for secure authentication.