This is an E-Commerce API built with Node.js, Express, TypeScript, and MySQL. It provides endpoints for managing users, products, and shopping carts (based on https://roadmap.sh/projects/ecommerce-api).
- User authentication and authorization using JWT
- Password hashing with bcrypt
- Product management (CRUD operations)
- Shopping cart management
- Checkout process with Stripe integration
- API documentation with Swagger
- Caching with Redis
- Logging with Winston
- Node.js (v14 or higher)
- MySQL
- Redis
- Stripe account
-
Clone the repository:
git clone https://github.com/akilkarthikeyan/ecommerce.git cd ecommerce
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add the following environment variables:PORT=3000 HOST=http://localhost DB_HOST=your_db_host DB_USER=your_db_user DB_PASSWORD=your_db_password DB_NAME=your_db_name REDIS_HOST=your_redis_host REDIS_PORT=6379 JWT_SECRET=your_jwt_secret STRIPE_SECRET_KEY=your_stripe_secret_key
-
Set up the database:
mysql -u your_db_user -p your_db_name < db_scripts/schema.sql
-
Run the development server:
npm run dev
-
Access the API documentation:
Open your browser and navigate to
http://localhost:3000/api-docs
to view the Swagger documentation.
- POST /api/users: Register a new user
- POST /api/users/login: Login a user and get a JWT token
- GET /api/products: Get a list of all products
- GET /api/products?search=searchTerm: Get list of products with name, description or category matching 'searchTerm'
- POST /api/products: Create a new product (requires admin role)
- PUT /api/products/:id: Update a product (requires admin role)
- DELETE /api/products/:id: Delete a product (requires admin role)
- GET /api/cart: Get the current user's cart
- POST /api/cart/add: Add an item to the cart
- DELETE /api/cart/remove/:id: Remove an item from the cart
- POST /api/cart/checkout: Process a checkout with Stripe
npm run dev
: Start the development server with nodemonnpm run build
: Compile TypeScript to JavaScriptnpm run start
: Start the production server
This project is licensed under the MIT License.