A full-featured e-commerce web application built with Node.js, Express, and MySQL, featuring real-time functionality with Socket.IO.
- Multi-user System: Support for customers, shop owners, and administrators
- Real-time Communication: Socket.IO integration for live updates
- Product Management: Complete CRUD operations for products and categories
- Shopping Cart: Session-based cart management
- Order Processing: Full order lifecycle management
- Admin Dashboard: Administrative interface for system management
- Responsive Design: Bootstrap-powered responsive UI
- Security: Input validation, session management, and CSRF protection
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Client Side │ │ Server Side │ │ Database │
│ │ │ │ │ │
│ ┌───────────┐ │ │ ┌───────────┐ │ │ ┌───────────┐ │
│ │ Bootstrap │ │ │ │ Express │ │ │ │ MySQL │ │
│ │ UI │ │ │ │ Router │ │ │ │ Database │ │
│ └───────────┘ │ │ └───────────┘ │ │ └───────────┘ │
│ ┌───────────┐ │ │ ┌───────────┐ │ │ ┌───────────┐ │
│ │ Socket.IO │◄─┼────┼─►│ Socket.IO │ │ │ │ Knex │ │
│ │ Client │ │ │ │ Server │ │ │ │ ORM │ │
│ └───────────┘ │ │ └───────────┘ │ │ └───────────┘ │
│ ┌───────────┐ │ │ ┌───────────┐ │ │ │
│ │ EJS │ │ │ │ EJS │ │ │ │
│ │Templates │ │ │ │ Renderer │ │ │ │
│ └───────────┘ │ │ └───────────┘ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Features
- Architecture
- Installation
- Configuration
- Usage
- API Endpoints
- Database Schema
- Deployment
- Contributing
- License
- Node.js (v16.12.0 or higher)
- MySQL (v5.7 or higher)
- npm or yarn package manager
-
Clone the repository
git clone https://github.com/abdoElHodaky/nodeJsEcommerce.git cd nodeJsEcommerce -
Install dependencies
npm install
-
Database setup
# Create MySQL database mysql -u root -p CREATE DATABASE ecommerce; # Import database schema mysql -u root -p ecommerce < e.sql
-
Configure database connection
# Edit knex.js with your database credentials cp knex.js.example knex.js
module.exports = {
development: {
client: 'mysql',
connection: {
host: 'localhost',
user: 'your_username',
password: 'your_password',
database: 'ecommerce'
}
}
};Create a .env file in the root directory:
PORT=3000
NODE_ENV=development
SESSION_SECRET=your_session_secret
DB_HOST=localhost
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=ecommercenpm startThe application will be available at http://localhost:3000
# Using PM2
npm install -g pm2
pm2 start app.js --name "ecommerce"
# Using Docker
docker build -t nodejs-ecommerce .
docker run -p 3000:3000 nodejs-ecommercePOST /login- User loginPOST /register- User registrationGET /logout- User logout
GET /products- List all productsGET /products/:id- Get product detailsPOST /products- Create new product (Admin)PUT /products/:id- Update product (Admin)DELETE /products/:id- Delete product (Admin)
POST /cart/add- Add item to cartGET /cart- View cart contentsPUT /cart/update- Update cart itemDELETE /cart/remove- Remove item from cart
POST /orders- Create new orderGET /orders- List user ordersGET /orders/:id- Get order details
GET /admin- Admin dashboardGET /admin/users- Manage usersGET /admin/orders- Manage ordersGET /admin/products- Manage products
-- Users and Authentication
adms (admID, Name, Password, Email, type)
clients (clientID, Name, Password, Email, Phone, Address)
owners (ownerID, Name, Password, Email, Phone, Address)
-- Products and Inventory
products (productID, Name, Description, Price, Stock, CategoryID)
categories (categoryID, Name, Description)
shops (shopID, Name, ownerID, Address, Phone)
-- Orders and Transactions
orders (orderID, clientID, Total, Status, CreatedAt)
order_items (orderItemID, orderID, productID, Quantity, Price)
bill (billID, orderID, Amount, PaymentMethod, Status)
-- Shopping Cart
cart (cartID, clientID, productID, Quantity, AddedAt)FROM node:16.12.0-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]# Install Heroku CLI
heroku create your-app-name
heroku addons:create cleardb:ignite
heroku config:set NODE_ENV=production
git push heroku master- Development: Local MySQL, debug logging enabled
- Staging: Cloud database, limited logging
- Production: Optimized for performance, error tracking
- Backend: Node.js, Express.js
- Database: MySQL with Knex.js ORM
- Frontend: EJS templating, Bootstrap 3
- Real-time: Socket.IO
- Security: Helmet, express-validator
- Session Management: express-session
- File Upload: Multer
# Run tests (when implemented)
npm test
# Run linting
npm run lint
# Check security vulnerabilities
npm audit- Response Time: Monitor API endpoint performance
- Database Queries: Optimize with proper indexing
- Memory Usage: Track Node.js memory consumption
- Error Tracking: Implement error logging and monitoring
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is released under The Unlicense - see the LICENSE file for details.
Abdo El Hodaky
- GitHub: @abdoElHodaky
- LinkedIn: Connect with me
- Live Demo: https://nodejse-commerce.herokuapp.com/
- Documentation: Wiki
- Issues: Bug Reports
⭐ Star this repository if you found it helpful!