This is a full-featured bilingual (English/Arabic) e-commerce backend built using Express.js/NestJS, MongoDB, and TypeScript. It includes JWT-based authentication, role-based access control (Admin/User), modular architecture, and follows JSend API response conventions.
- ✅ JWT Authentication & Authorization
- ✅ Role-Based Access Control (Admin/User)
- ✅ RESTful APIs following JSend
- ✅ Modular & Scalable Project Structure
- ✅ MongoDB (with Mongoose)
- ✅ Cart & Order Management
- ✅ Product & Category CRUD
- ✅ Bilingual Localization (English / Arabic)
- Backend: Express.js / NestJS + TypeScript
- Database: MongoDB + Mongoose
- Auth: JWT
- Language Support: i18n (nestjs-i18n)
- Validation: class-validator
- Node.js v18+
- MongoDB (local or cloud)
- npm or yarn
git clone https://github.com/re00zq/Node.js-E-commerce
cd Node.js-E-commerce
npm installCreate a .env file in the root directory:
#DATABASE CONFIGURATION
DATABASE_HOST=localhost
DATABASE_PORT=27017
DATABASE_USERNAME=mongodb
DATABASE_NAME=e-commerce
#JWT access token
JWT_SECRET=thisIsveryStrongSecretForJwt
JWT_EXPIRED_IN="1m"
#JWT refresh token
JWT_REFRESH_SECRET=thisIsVeryStrongRefreshSecretForJwt
JWT_REFRESH_EXPIRED_IN="30D"
#JWT confirmation token
JWT_CONFIRMATION_SECRET="THIS+IS+VERY+STRONG+PASSWORD"
JWT_CONFIRMATION_EXPIRED_IN="1D"
#MAIL
MAIL_HOST=smtp.gmail.com
MAIL_SERVICE=gmail
SMTP_USERNAME=your.email@gmail.com
SMTP_PASSWORD="your-SMTP-password"
SMTP_PORT=587
#SERVER
HOST=localhost
PORT=3000
URL=http://localhost:3000# development
npm run start:dev
# production
npm run build
npm run start:prodThis app supports both Arabic and English using nestjs-i18n.
To change language:
- Add a request header:
x-lang: enorx-lang: ar - Or send a query parameter:
lang=enorlang=ar
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
User registration |
| POST | /auth/login |
Login (JWT token) |
| POST | /auth/refresh |
Refresh Token |
| POST | /auth/logout |
Logout |
| POST | {ConfirmToken} |
Confirm Email |
| Method | Endpoint | Description |
|---|---|---|
| GET | /products |
List all products |
| GET | /products/:id |
Find Product |
| POST | /products |
Create (Admin only) |
| PATCH | /products/:id |
Update (Admin only) |
| DELETE | /products/:id |
Delete (Admin only) |
| GET | /products/search?q=query |
Search in products |
| Method | Endpoint | Description |
|---|---|---|
| GET | /categories |
List all categories |
| POST | /categories |
Create (Admin only) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
List users (Admin only) |
| Method | Endpoint | Description |
|---|---|---|
| POST | /orders/make |
Make an Order |
| GET | /orders |
List orders (Admin only) |
| GET | /orders/mine |
Get user order |
| DELETE | /orders/mine |
Delete user order |
| DELETE | /orders |
Delete order (Admin only) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /cart |
Get current user cart |
| POST | /cart/add |
Add product to cart |
| PATCH | /cart/update |
Update quantity |
| DELETE | /cart/remove/:id |
Remove item from cart |
| DELETE | /cart/clear |
Clear all cart items |
- User: Can view all products and manage their own cart and orders
- Admin: Can manage products, categories, and all orders
Every response follows the JSend specification:
{
"status": "success",
"data": { "product": { "name": "Phone" } }
}The ERD diagram for the collections is included as a .drawio file inside the project folder:
📁 docs/ecommerce-erd.drawio
To view it, open the file using draw.io.
You can test all API endpoints through this Postman workspace:
Make sure to configure the
.envfile before using the collection.
Happy Coding! 🚀