Coder Social home page Coder Social logo

milan-sony / e-commerce_application Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 254 KB

An E-Commerce Application build with Node.js, Express.js, Handlebars , AJAX and MongoDB

JavaScript 54.80% Handlebars 45.20%
ecommerce-application ecommerce-platform ecommerce-website express hbs mongodb mongoose node-js nodejs expressjs ajax jquery handlebars

e-commerce_application's Introduction

#LearnNodeJS

E-Commerce Application

An E-Commerce Application build with Node.js, Express.js, Handlebars , AJAX and MongoDB

โณ Timeline

Day 1

๐Ÿ“… 20/01/2024

  • index page created

  • layout folder created

  • partial folder created

  • libraries installed

    • npm install nodemon auto restart server

    • npm install express-handlebars for adding layout and partial folder

      • To set the path of layout and partial folder (inside app.js)

        app.engine('hbs', hbs.engine({
          extname: 'hbs',
          defaultLayout: 'layout',
          layoutsDir: __dirname + '/views/layout/',
          partialsDir: __dirname + '/views/partials'
        }));
    • npm install express-fileupload file upload

      app.use(fileUpload());
  • added products to the index page by passing a products object and displayed using hbs template

  • create separate page for admin and user

  • admin panel created

  • added products to the admin panel by passing a products object and displayed it in table format

  • added add new product form for admin

Day 2

๐Ÿ“… 21/02/2024

  • Mongoose Connected

    const mongoose = require('mongoose');
    const url = "mongodb://127.0.0.1:27017/mydb";
    
    module.exports = {
    
        connect: () => {
            mongoose.connect(url)
            .then(() => {
                console.log("Connected to MongoDB\n");
            }).catch((error) => {
                console.log(error);
            });
        },
    
        collection: (name) => {
            return mongoose.connection.db.collection(name);
        }
    
    };

    This code exports an object with two methods, connect and collection, using Node.js CommonJS module system. Let's break down each part:

    1. Importing Mongoose:

      const mongoose = require('mongoose');

      This line imports the Mongoose library, which allows interaction with MongoDB databases using an object modeling approach.

    2. Defining MongoDB URL

      const url = "mongodb://127.0.0.1:27017/mydb";

      This line defines the URL used to connect to the MongoDB database. It specifies the protocol (mongodb://), the host (127.0.0.1 or localhost), the port (27017), and the name of the database (mydb).

    3. Exporting Module:

      module.exports = {
          // methods...
      };

      This code exports an object containing methods using module.exports, making these methods accessible to other parts of the application.

    4. Connect Method:

      connect: () => {
          mongoose.connect(url)
          .then(() => {
              console.log("Connected to MongoDB\n");
          }).catch((error) => {
              console.log(error);
          });
      },

      This method establishes a connection to the MongoDB database specified by the URL. It uses mongoose.connect() to connect to MongoDB asynchronously. If the connection is successful, it logs a success message to the console. If there's an error during the connection process, it logs the error.

    5. Collection Method:

      collection: (name) => {
          return mongoose.connection.db.collection(name);
      }

      This method returns a MongoDB collection object based on the provided collection name. It uses mongoose.connection.db.collection(name) to access the specified collection through the Mongoose connection.

      Overall, this module provides a way to connect to a MongoDB database and access collections within that database using Mongoose. Other parts of the application can import this module and use its methods to interact with the database.

  • helper folder created for products

  • product details added to database

  • product image saved to product_image folder in public folder

โš  Error occurred: image is not displayed from product_image folder

Day 3

๐Ÿ“… 22/02/2024

  • Error fixed image is displayed from the product_image folder
  • product data added to user side
  • user login and signup page created
  • user signup data saved to db
  • user login and page redirected
  • user session created
  • user logout

Day 4

๐Ÿ“… 23/02/2024

  • user valid or invalid checked
  • cart page created
  • middleware created for checking the user login
  • product deleted from admin side

Day 5

๐Ÿ“… 25/02/2024

  • product details displayed on another page for editing
  • product details updated and image changed
  • user signup session created
  • working on add to cart

Day 7

๐Ÿ“… 28/02/2024

  • Add to cart count updated with Ajax
  • cart item and quantity displayed

Day 8

๐Ÿ“… 29/02/2024

  • cart product quantity increased and decreased

Day 9

๐Ÿ“† 01/03/2024

  • Product removed from cart
  • product checkout page created

Day 10

๐Ÿ“† 02/03/2024

  • Total price added on place_order.hbs page
  • Total price added on cart.hbs
  • payment methods created
  • Order collection created and product removed from cart
  • product details listed on orders.hbs
  • product checkout created
  • Cart error fixed
  • Admin view all users added
  • Admin search product
โš™ Run locally

You will need to install Node.js and MongoDB on you system

Head over to https://nodejs.org/en to download Node.js

Head over to https://www.mongodb.com/try/download/community to download MongoDB community server

Make sure Node and NPM are installed and their PATHs defined

Once you have downloaded Node.js and MongoDB run the following command (clone this project)

  https://github.com/milan-sony/e-commerce_application.git

Then go to the project folder

  cd e-commerce_application

Install the dependencies/ packages needed for this project

  npm install

Once the packages are installed run

  npm start

Then head over to a browser and type

  localhost:3000

e-commerce_application's People

Contributors

milan-sony avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.