A modern, secure e-commerce platform built with Node.js, Express, MongoDB, and Passport.js.
- User Authentication: Secure login/register with Passport.js
- Product Management: CRUD operations for products
- Shopping Cart: Add/remove items from cart
- Reviews & Ratings: Product reviews system
- Responsive Design: Modern UI with EJS templates
- Security: Helmet, CORS, Rate limiting, Input sanitization
- Production Ready: Environment-based configuration
- Node.js >= 18.0.0
- npm >= 8.0.0
- MongoDB (local or cloud)
-
Clone the repository
git clone https://github.com/yourusername/shopiko.git cd shopiko -
Install dependencies
npm install
-
Environment Setup
# Copy the example environment file cp .env.example .env # Edit the .env file with your configuration nano .env
-
Database Setup
# Start MongoDB (if using local) mongod # Or use MongoDB Atlas (cloud) # Update MONGO_URI in .env file
-
Start the application
# Development mode npm run dev # Production mode npm start
Create a .env file in the root directory:
# Application
NODE_ENV=development
PORT=8080
# Database
MONGO_URI=mongodb://localhost:27017/shopiko
# Security
SECRET=your-super-secret-key-change-this-in-production
SESSION_SECRET=another-super-secret-session-key-change-this
# Optional: For production features
JWT_SECRET=your-jwt-secret-key
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-passwordshopiko/
βββ config/
β βββ config.js # Application configuration
βββ middlewares/
β βββ middlewares.js # Authentication middleware
β βββ security.js # Security middleware
βββ models/
β βββ Product.js # Product model
β βββ Review.js # Review model
β βββ User.js # User model
βββ routes/
β βββ api/
β β βββ productapi.js # API routes
β βββ auth.js # Authentication routes
β βββ cart.js # Cart routes
β βββ productRoutes.js # Product routes
β βββ review.js # Review routes
β βββ static.js # Static pages
βββ views/ # EJS templates
βββ public/ # Static assets
βββ app.js # Main application file
βββ package.json # Dependencies
βββ README.md # This file
- Helmet.js: Security headers
- CORS: Cross-origin resource sharing
- Rate Limiting: Prevent abuse
- Input Sanitization: XSS protection
- Session Security: Secure session configuration
- Environment Variables: Secure configuration management
# Set production environment
NODE_ENV=production
# Use strong secrets
SECRET=your-very-long-random-secret-key
SESSION_SECRET=another-very-long-random-session-secret
# Database (use MongoDB Atlas or cloud database)
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/shopiko
# Disable debug mode
DEBUG=false# Install PM2
npm install -g pm2
# Start application
pm2 start app.js --name "shopiko"
# Monitor
pm2 monit
# Logs
pm2 logs shopikoserver {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}# Install Certbot
sudo apt install certbot python3-certbot-nginx
# Get certificate
sudo certbot --nginx -d yourdomain.com# Run tests (when implemented)
npm test
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix- Health Check:
GET /health - Application Info:
GET /test - Logs: Check console output and log files
# Start development server with auto-reload
npm run dev
# Install new dependencies
npm install package-name
# Update dependencies
npm updatePOST /auth/register- Register new userPOST /auth/login- Login userGET /auth/logout- Logout user
GET /products- List all productsPOST /products- Create new productGET /products/:id- Get product detailsPATCH /products/:id- Update productDELETE /products/:id- Delete product
GET /cart- View cartPOST /cart/:id- Add to cartDELETE /cart/:id- Remove from cart
POST /api/products/:productId/like- Like/unlike product
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the ISC License.
- Issues: GitHub Issues
- Documentation: Check the code comments and this README
- Security: Report security issues privately
- Initial release
- Basic e-commerce functionality
- Security middleware
- Production-ready configuration
Built with β€οΈ using Node.js, Express, MongoDB, and Passport.js