https://github.com/asbdaryaee/node.js_e-commerce_api
Full E-Commerce API written in Node.js, Express.js and MongoDB.
https://github.com/asbdaryaee/node.js_e-commerce_api
e-commerce e-commerce-project ecommerce ecommerce-application express mongodb mongoose node nodejs
Last synced: 3 months ago
JSON representation
Full E-Commerce API written in Node.js, Express.js and MongoDB.
- Host: GitHub
- URL: https://github.com/asbdaryaee/node.js_e-commerce_api
- Owner: AsbDaryaee
- License: apache-2.0
- Created: 2023-05-18T17:00:30.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-20T20:26:02.000Z (5 months ago)
- Last Synced: 2025-02-20T21:29:10.877Z (5 months ago)
- Topics: e-commerce, e-commerce-project, ecommerce, ecommerce-application, express, mongodb, mongoose, node, nodejs
- Language: JavaScript
- Homepage:
- Size: 82 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# E-commerce API
This is a Node.js API for an e-commerce website. It provides endpoints for authentication, user management, product management, review management, and order management.
## Installation
1. Clone this repository
2. Install dependencies using `npm install`
3. Set environment variables:
- `PORT`: The port number to run the server on (default is 3000)
- `MONGO_URI`: The MongoDB connection URI
- `JWT_SECRET`: The secret key for JSON Web Tokens
4. Start the server using `npm start`## Endpoints
### Authentication
- POST `/api/v1/auth/register`: Register a new user
- POST `/api/v1/auth/login`: Log in an existing user
- GET `/api/v1/auth/logout`: Log out an existing user### Users
- GET `/api/v1/users`: Get all users (admin only)
- GET `/api/v1/users/:id`: Get a single user by ID (admin or authenticated user only)
- PATCH `/api/v1/users/:id`: Update a user by ID (admin or authenticated user only)
- DELETE `/api/v1/users/:id`: Delete a user by ID (admin only)
- GET `/api/v1/users/ShowMe`: Get the current user's profile### Products
- GET `/api/v1/products`: Get all products
- GET `/api/v1/products/:id`: Get a single product by ID
- POST `/api/v1/products`: Create a new product (Admin Or Registerd Users)
- PATCH `/api/v1/products/:id`: Update a product by ID (admin or owner)
- DELETE `/api/v1/products/:id`: Delete a product by ID (admin only or owner)### Reviews
- GET `/api/v1/reviews`: Get all reviews
- GET `/api/v1/reviews/:id`: Get a single review by ID
- POST `/api/v1/reviews`: Create a new review (authenticated user only)
- PATCH `/api/v1/reviews/:id`: Update a review by ID (admin or the review author only)
- DELETE `/api/v1/reviews/:id`: Delete a review by ID (admin or the review author only)### Orders
- GET `/api/v1/orders`: Get all orders (admin only)
- GET `/api/v1/orders/:id`: Get a single order by ID (admin or the order owner only)
- POST `/api/v1/orders`: Create a new order (authenticated user only)
- PATCH `/api/v1/orders/:id`: Update an order by ID (admin only)## Error Handling
If an error occurs in any endpoint, it will be handled by the `errorHandler` middleware and returned as a JSON response with the following properties:
- `status`: The HTTP status code of the error (e.g. 400, 404, 500)
- `message`: A human-readable error message
- `stack`: A stack trace for debugging purposes (only included in development mode)