This is the backend API for an e-commerce platform built using Node.js, Express, and TypeScript.
Postman Link - Postman
To get started with this project, follow these steps:
Make sure you have the following installed:
- Node.js (version >= 14)
- npm or yarn
- Clone the repository
git clone https://github.com/yourusername/ecommerce-backend.git
- Navigate to the project directory
cd ecommerce-backend
- Install dependencies:
npm install
oryarn install
- Set up environment variables:
- Create a
.env
file based on.env.example
and set the necessary environment variables.
- Create a
to start the server, run:
npm start
oryarn start
For development purposes, you can run the server in watch mode using:
npm run dev
oryarn dev
This will enable hot reloading usingnodemon
and allow you to see changes without restarting the server manually.
The following endpoints are available:
POST /api/signup
: Creates a user.POST /api/login
: Login a user.POST /api/logout
: Logs out the user,
POST /api/admin-signup
: Creates a user.POST /api/admin-login
: Login a user.POST /api/admin-logout
: Logs out the user,PUT /api/authorise-seller
: Authorises a user to be a seller.
POST /api/addtocart
: Adds a specific product to the cart of the user.GET /api/get-items
: Retrieves the products in the user cart.DELETE /api/delete-product
: Deletes a specific product from the cart.DELETE /api/empty-cart
: Empties the cart of the user.
POST /api/order
: Creates an order using the cart of the user.PUT /api/cancel-order
: Cancels the existing order of the user using orderId.
POST /api/create-product
: Creates a product to sell .
Every day at 23:00
a cron service runs which checks all orders for cancelled and then settles payment to the seller.
src/
- Contains the source code.controllers/
- Controllers handling the API Logic.models/
- Data models and database schemas.routes/
- API routes.middleware/
- Contains the Authorisation & Authentication Logic.services/
- Contains the functions directly communicating with the server.utility/
- Contains the utility functions.db/
- Contains the logic to connect to themongodb
database.
dist/
- Compiled Typescript files (generated onbuild).
- Node.js
- Express.js
- TypeScript