This is a fully functional E-Commerce backend API built using Node.js, designed to handle a range of features such as user authentication, role-based access, product management, and order processing with cash and Stripe payment integration.
-
π User Authentication & Authorization:
- JWT-based authentication.
- Email verification using a verification code.
- Role-based access control (Admin, Manager, User).
-
ποΈ Product & Category Browsing:
- Browse products and categories without authentication.
- Support for sub-categories.
-
π Shopping Cart:
- Add products to the shopping cart for registered users.
-
π¦ Order Management:
- Create and manage orders.
- Support for discount coupons.
-
π³ Payment Integration:
- Cash payments.
- Stripe integration for card payments.
-
π Admin Features:
- Manage users, products, categories, and orders.
- Upload and manage product images.
-
π Search & Filtering:
- Advanced search functionality.
- Filtering, sorting, pagination, and field limiting.
-
π Security:
- Data validation.
- Rate limiting to prevent abuse.
- HTTP Parameter Pollution (HPP) protection.
- Data sanitization against XSS and NoSQL injection.
-
β‘ Performance Optimization:
- Support for compression.
- CORS enabled for cross-origin requests.
-
Clone the repository:
git clone https://github.com/Ahmad-Nour-Haidar/nodejs-ecommerce-api.git
-
Navigate to the project directory:
cd nodejs-ecommerce-api
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory with the following:# Environment Variables # The port on which the server will run PORT=3000 # Environment setting: 'development' or 'production' NODE_ENV=development #NODE_ENV=production # MongoDB credentials and connection details # Database username for MongoDB DB_USER= # Database password for MongoDB DB_PASSWORD= # Name of the database DB_NAME=nodejs-ecommerce-api # Base URL for the application BASE_URL=http://localhost:3000/ # Local MongoDB connection URI MONGODB_URI=mongodb://127.0.0.1:27017/udemy-ecommerce # Remote MongoDB connection URI (Atlas Cluster) MONGODB_URI_REMOTE= # JWT (JSON Web Token) secret and expiration time # Secret key for signing JWTs JWT_SECRET_KEY= # Expiration time for JWTs JWT_EXPIRE_TIME=90d # Email Settings # Email used for sending emails EMAIL_USER= # Email account password (should be securely stored) EMAIL_PASSWORD= # "From" email address used when sending emails EMAIL= # SMTP host for sending emails EMAIL_HOST=smtp.gmail.com # SMTP port for secure email transmission EMAIL_PORT=465 # Stripe Configuration # Stripe secret for payments STRIPE_SECRET= # Webhook secret for Stripe STRIPE_WEBHOOK_SECRET=
-
Start the server:
nodemon app.js
This project is built as part of a training course on Udemy: E-Commerce Backend with Node.js
This project is licensed under the MIT License - see the LICENSE file for details.