This project is a simple product management API built using Node.js, Express, and MySQL. It allows you to create, read, update, and delete (CRUD) products in a MySQL database. The project uses environment-based configurations to manage different database credentials for development and production environments.
Before you begin, ensure you have the following installed:
-
Clone the repository
git clone https://github.com/kavienanj/single_vendor_ecommerce.git
-
Navigate to the backend directory
cd single_vendor_ecommerce/backend
-
Install dependencies
Run the following command to install the necessary dependencies:
npm install
-
Set up the environment file
Create a
.env
file in thebackend
directory with the following content:DB_HOST=localhost DB_USER=root DB_PASSWORD=your_password DB_NAME=ECommerceDatabase JWT_SECRET=your_secret_key
Replace
your_password
with your actual MySQL password. -
Run the SQL script
Run the following command to create the database and table:
cd .. mysql -u root -p < FinalDatabase.sql
Enter your MySQL password when prompted.
-
Run the server
To start the server, and listen for changes, run the following command:
cd backend npm run dev
The server will start on the port
3000
defined in theserver.js
file. Make sure the port is3000
. If not do not forget to change the port in theAPI_HOSTNAME
variable infrontend/src/services/axiosClient.ts
file. -
Setup the frontend
The Next.js frontend is located in the
frontend
directory. To run the frontend, navigate to thefrontend
directory and run the following command:cd frontend npm install npm run dev
The frontend will start on the port
3001
.
├── backend/
│ ├── routes/ # Express routing
│ ├── controllers/ # API controllers
│ ├── models/ # Database models
| ├── middleware/ # Middleware functions
│ ├── db.js # Database connection logic
│ ├── server.js # Main server setup and middleware
│ ├── package.json # Backend dependencies and scripts
│ └── .env # Environment variables
|-- frontend/
| ├── src/
| | ├── app/ # Main app component
| | ├── components/ # React components
| | └── services/ # API service
| └── package.json # Frontend dependencies and scripts
├── .gitignore # Git ignore file
├── FinalDatabase.sql # SQL script for creating the database and table
└── README.md # Project documentation
KAVIENAN J. 220314M [email protected] PANAGODA P.L.A.S. 220440U [email protected] RAVISHAN A.D.P. 220532E [email protected] JAYARATNE T.D. 220254D [email protected] LOKUHEWA P.C. 220366X [email protected]