Ecommerce CRUD API
A simple CRUD application built with Node.js (Express) and MySQL. This project demonstrates how to build and test RESTful APIs connected to a relational database. Features REST API built with Express MySQL database connection using mysql2 CRUD operations for Users (and extendable to Products, Orders, etc.) API tested with Thunder Client Database Setup Install and open MySQL Workbench (or CLI). Run the SQL schema file: source Ecommerce schema.sql; Verify the database and tables were created:
SHOW DATABASES; USE ecommerce; SHOW TABLES;
Installation & Setup Clone or download this repository. Install dependencies: npm install Configure your database connection in a .env file:
DB_HOST=localhost DB_USER=root DB_PASSWORD=your_mysql_password DB_NAME=ecommerce PORT=3000 Start the server: node server.js Server will run on http://localhost:3000 . API Endpoints Root GET / → Check server & DB connection Users POST /users → Create new user
{ "email": "alice@example.com", "password_hash": "secret123", "first_name": "Alice", "last_name": "Johnson" }
GET /users → Fetch all users PUT /users/:id → Update user by ID DELETE /users/:id → Delete user by ID Testing Import the provided Thunder Client collection (thunder-collection.json) into VS Code.
Project Structure ecommerce-crud/ │── server.js # Main Express server │── db.js # MySQL connection pool │── Ecommerce schema.sql # Database schema │── package.json │── README.md │── thunder-collection.json (optional)
Author- Albright Njeri Njoroge