This repository contains a simple Ecommerce API for managing products and variants. The API is built using Node.js, Express, and MongoDB.
Follow the steps below to run the project locally:
- Clone the repository:
git clone https://github.com/himacharan128/ecommerce-api.git
- Install dependencies:
cd ecommerce-api
npm install
- Create a .env file in the root directory and set the MongoDB connection URI:
MONGODB_URI=your_mongodb_connection_uri
- Start the server:
node index.js
The server will be running at http://localhost:3000.
Endpoints
- POST /products: Create a new product.
- GET /products: Get all products.
- GET /products/:productId: Get a specific product by ID.
- GET /products/search?query=example: Search products by name, description, or variant name.
- PUT /products/:productId: Update a product by ID.
- DELETE /products/:productId: Delete a product by ID.
- POST /products/:productId/variants: Create a variant for a specific product.
- PUT /products/:productId/variants/:variantId: Update a variant for a specific product.
- DELETE /products/:productId/variants/:variantId: Delete a variant for a specific product.
- src/controllers: Contains the controllers for handling API requests.
- src/models: Defines the Mongoose schemas for products and variants.
- src/routes: Defines the API routes.
- src/tests: Contains test files (not implemented in this example).
- index.js: Main entry point for the application.
- .env: Environment variable configuration file .
- Express: A fast, unopinionated, minimalist web framework for Node.js.
npm install express
- Mongoose: MongoDB object modeling tool designed to work in an asynchronous environment.
npm install mongoose
- Body-Parser: Node.js body parsing middleware to parse incoming request bodies.
npm install body-parser
- Dotenv: Zero-dependency module that loads environment variables from a .env file.
npm install dotenv
Contributions are welcome! If you have any ideas for improvement or would like to report an issue, please open an issue or submit a pull request.