UniCart is an e-commerce web application designed to provide a seamless online shopping experience. This project leverages Express.js for the backend, EJS for templating, and Axios for making API requests. The application supports browsing products across various categories, featuring new and discounted items, and more.
- Dynamic Rendering: Products and categories are dynamically fetched from an external API.
- Random Discounts: Each category page features a randomly selected discounted product.
- Responsive Design: The application is fully responsive, with a mobile-friendly layout.
- Multi-language Support: Users can select their preferred language and currency.
- Customizable UI: Easy to modify and extend the front-end design.
Currently, there is no "Add to Cart" feature implemented. This functionality will be added in a future update.
A login and signup feature will be implemented in the future to allow users to create accounts and manage their purchases more efficiently.
- Node.js (version 12 or higher)
- npm (version 6 or higher)
-
Clone the repository:
git clone https://github.com/yourusername/unicart.git cd unicart
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory and add the following:API_URL="https://api.escuelajs.co/api/v1" PORT=3000
-
Run the application:
npm start
-
Open your browser and navigate to
http://localhost:3000
.
UniCart uses the EscuelaJS Fake Store API to fetch product data. Below are examples of how to fetch data using this API.
To fetch all products, you can use the following code snippet:
fetch('https://api.escuelajs.co/api/v1/products')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error fetching products:', error));
To fetch a specific product by its ID, use the following code:
const productId = 1; // Replace with the actual product ID
fetch(`https://api.escuelajs.co/api/v1/products/${productId}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(`Error fetching product with ID ${productId}:`, error));
To fetch all categories, you can use this code snippet:
fetch('https://api.escuelajs.co/api/v1/categories')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error fetching categories:', error));
unicart/
│
├── public/ # Static assets (CSS, images, etc.)
│ ├── css/
│ ├── images/
│ └── ...
│
├── views/ # EJS templates
│ ├── partials/
│ ├── category/
│ ├── pages/
│ └── product/
│
├── .env # Environment variables
├── app.js # Express application
├── package.json # NPM package file
└── ...
app.js
: The main server file, where routes and middleware are defined.views/
: Contains EJS templates for rendering the front end.partials/
: Reusable partial templates (header, footer, etc.).category/
: Templates for different product categories.pages/
: Main pages (home, filtered categories).product/
: Templates for individual product components.
/
: Home page displaying featured products, new products, and various sections./clothes
: Category page for clothes./electronics
: Category page for electronics./furniture
: Category page for furniture./footwear
: Category page for footwear.
- Create a new template in the
views/category
directory. - Add a new route in
app.js
similar to the existing category routes. - Update the navigation in
views/partials/header.ejs
to include the new category.
- CSS: Modify the CSS files in
public/css/
. - Templates: Edit the EJS templates in the
views/
directory.
Contributions are welcome! Please fork the repository and create a pull request with your changes. Make sure to follow the existing code style and include appropriate tests.
This project is licensed under the MIT License. See the LICENSE file for details.