This is the backend server for the E-Cart e-commerce application. It provides the API endpoints and handles database operations for the application.
Follow these steps to set up the backend server locally on your machine.
Before you begin, ensure you have the following installed:
- Node.js and npm (Node Package Manager) or yarn
- MongoDB (Make sure it's running locally or adjust the
MONGODB_URI
in the.env
file accordingly)
-
Clone the repository:
git clone https://github.com/sailesh307/e-cart.git
-
Navigate to the backend directory:
cd backend
-
Install the dependencies:
yarn install
-
Create a
.env
file in the root directory and add the following environment variables:MONGODB_URI=<your-mongodb-uri> JWT_SECRET=<your-jwt-secret>
example:
MONGODB_URI=mongodb://localhost:27017/e-cart JWT_SECRET=secret
Note: The
JWT_SECRET
can be any string of your choice. -
Start the server:
yarn start
The server should now be running on
http://localhost:5000
.
-
api/users
: User-related endpointsPOST /api/users/register
: Register a new userPOST /api/users/login
: Login an existing userGET /api/users/profile
: Get the profile of the currently logged in user
-
api/products
: Product-related endpointsGET /api/products
: Get all products on searchGET /api/products/id/:id
: Get a product detail by idPOST /api/products
: Create new productsPUT /api/products/id/:id
: Update a product by idDELETE /api/products/id/:id
: Delete a product by id
-
api/cart
: Cart-related endpointsGET /api/cart
: Get the cart of the currently logged in userDELETE /api/cart/:id
: Delete an item from the cartPUT /api/cart/:id
: Update an item in cart of the currently logged in user
Contributions are welcome! Feel free to open issues or pull requests for any improvements or features you'd like to add.