Repository navigation
Express API with MySQL2 π
This is a simple CRUD API built with Express.js and MySQL2 for managing products, invoices, and inventory. π
Features β¨
- π RESTful API with organized structure.
- π Models, Repositories, and Services for clean separation of concerns.
- π‘οΈ Middleware for validation and error handling.
- ποΈ MySQL2 integration for database operations.
- π§ͺ Ready for testing and scaling.
Prerequisites π
- Node.js (v14 or higher).
- MySQL/MariaDB setup (e.g., via XAMPP or Docker).
- A
.envfile configured with the following:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=store
PORT=3000Installation π οΈ
-
Clone the repository:
git clone https://github.com/Bardolog1/Basic-API-Express-Store.git cd Basic-API-Express-Store -
Install dependencies:
npm install
-
Configure the
.envfile. -
Initialize the database:
- Create a database named
store(or use the name specified in your.env). - Run the provided SQL scripts to create tables (
products,invoices,inventory).
- Create a database named
Usage π
Start the Server
npm startThe server will run on http://localhost:3000 by default.
Endpoints π‘
-
Products:
GET /api/products: Retrieve all products.GET /api/products/:id: Retrieve a product by ID.POST /api/products: Add a new product.PUT /api/products/:id: Update a product by ID.DELETE /api/products/:id: Delete a product by ID.
-
Invoices:
GET /api/invoices: Retrieve all invoices.GET /api/invoices/:id: Retrieve an invoice by ID.POST /api/invoices: Add a new invoice.PUT /api/invoices/:id: Update an invoice by ID.DELETE /api/invoices/:id: Delete an invoice by ID.
-
Inventory:
GET /api/inventory: Retrieve all inventory items.GET /api/inventory/:id: Retrieve inventory details by ID.GET /api/inventory/product/:productId: Retrieve inventory by product ID.POST /api/inventory: Add a new inventory item.PUT /api/inventory/:id: Update inventory by ID.
Project Structure ποΈ
project-root
βββ src
β βββ config
β β βββ db.config.js # Database configuration
β βββ controllers # Route controllers
β βββ middlewares # Middleware functions
β βββ models # Entity definitions
β βββ repositories # Database query logic
β βββ routes # API route definitions
β βββ errors # Custom error classes
β βββ services # Business logic
βββ app.js # Express app configuration
βββ server.js # Application entry point
βββ README.md # Project documentation
Contributing π€
- Fork the repository.
- Create your feature branch:
git checkout -b feature-name. - Commit your changes:
git commit -m 'Add some feature'. - Push to the branch:
git push origin feature-name. - Submit a pull request.
License π
This project is licensed under the MIT License. See the LICENSE file for details.
Made with β€οΈ by Bardolog1 β¨
Full Changelog: https://github.com/Bardolog1/Basic-API-Express-Store/commits/1.0.0