Code Monkey home page Code Monkey logo

bestbags-nodejs-ecommerce's Introduction

BestBags

Table of contents

Introduction

A virtual ecommerce website using Node js, Express js, and Mongoose.

NOTE: Please read the RUN section before opening an issue.

Demo

screenshot

The application is deployed to Heroku and can be accessed through the following link:

BestBags on Heroku

The website resembles a real store and you can add products to your cart and pay for them. If you want to try the checkout process, you can use the dummy card number provided by stripe for testing which is 4242 4242 4242 4242 with any expiration date, CVC, and zip codes. Please DO NOT provide real card number and data.

In order to access the admin panel on "/admin" you need to provide the admin email and password.

Run

To run this application, you have to set your own environmental variables. For security reasons, some variables have been hidden from view and used as environmental variables with the help of dotenv package. Below are the variables that you need to set in order to run the application:

  • MONGO_URI: this is the connection string of your MongoDB Atlas database.

  • SESSION_SECRET: a secret message for the session. You can use any string here.

  • STRIPE_PRIVATE_KEY: the stripe package is used to process payment in the checkout route. To get this, you should set up a stripe account and put your private API key here.

  • GMAIL_EMAIL, GMAIL_PASSWORD: the email and password given to nodemailer to send/receive the email. Please put a real email and password here because you will receive the messages sent from the contact us form on this email.

  • ADMIN_EMAIL, ADMIN_PASSWORD: the email and password used to log into the admin panel using AdminBro. You can put any email and password here.

  • ADMIN_COOKIE_NAME, ADMIN_COOKIE_PASSWORD: the cookie name and password used in the AdminBro authentication method. You can put any strings here.

After you've set these environmental variables in the .env file at the root of the project, you need to navigate to the "seedDB" folder and run "node category-seed.js" and "node products-seed.js" to fill your empty MongoDB Atlas database.

Now you can run "npm start" in the terminal and the application should work.

Technology

The application is built with:

  • Node.js version 12.16.3
  • MongoDB version 4.2.0
  • Express version 4.16.1
  • Bootstrap version 4.4.1
  • FontAwesome version 5.13.0
  • Stripe API v3: used for payment in the checkout page
  • Mapbox API: used to show the map in the about us page
  • AdminBro: used and customized to implement the admin panel
  • Nodemailer: used to send emails from the contact us form
  • Passport: used for authentication
  • Express Validator: used for form validation

Features

The application displays a virtual bags store that contains virtual products and contact information.

Users can do the following:

  • Create an account, login or logout
  • Browse available products added by the admin
  • Add products to the shopping cart
  • Delete products from the shopping cart
  • Display the shopping cart
  • To checkout, a user must be logged in
  • Checkout information is processed using stripe and the payment is send to the admin
  • The profile contains all the orders a user has made

Admins can do the following:

  • Login or logout to the admin panel
  • View all the information stored in the database. They can view/add/edit/delete orders, users, products and categories. The cart model cannot be modified by an admin because a cart is either modified by the logged in user before the purchase or deleted after the purchase.

Database

All the models can be found in the models directory created using mongoose.

User Schema:

  • username (String)
  • email (String)
  • password (String)

Category Schema:

  • title (String)
  • slug (String)

Product Schema:

  • productCode (String)
  • title (String)
  • imagePath (String)
  • description (String)
  • price (Number)
  • category (ObjectId - a reference to the category schema)
  • manufacturer (String)
  • available (Boolean)
  • createdAt (Date)

Cart Schema:

  • items: an array of objects, each object contains:
    ~ productId (ObjectId - a reference to the product schema)
    ~ qty (Number)
    ~ price (Number)
    ~ title (String)
    ~ productCode (Number)
  • totalQty (Number)
  • totalCost (Number)
  • user (ObjectId - a reference to the user schema)
  • createdAt

    **The reason for including the title, price, and productCode again in the items object is AdminBro. If we are to write our own admin interface, we can remove them and instead populate a product field using the product id. However, AdminBro doesn't populate deep levels, so we had to repeat these fields in the items array in order to display them in the admin panel.

Order Schema:

  • user (ObjectId - a reference to the user schema)
  • cart (instead of a reference, we had to structure an object identical to the cart schema because of AdminBro, so we can display the cart's contents in the admin interface under each order)
  • address (String)
  • paymentId (String)
  • createdAt (Date)
  • Delivered (Boolean)

Colors

Below is the color palette used in this application:

  • #478ba2 #478ba2
  • #b9d4db #b9d4db
  • #e9765b #e9765b
  • #f2a490 #f2a490
  • #de5b6d #de5b6d
  • #18a558 #18a558
  • #f9f7f4 #f9f7f4
  • #202020 #202020
  • #474747 #474747

License

License

bestbags-nodejs-ecommerce's People

Contributors

maryamaljanabi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bestbags-nodejs-ecommerce's Issues

HI! i found this error how can i solve

TypeError: C:\Users\vaish\bestbags-nodejs-ecommerce\views\shop\home.ejs:52
50| <% for(let i=0; i<3; i++){ %>
51|

52|
53| category
54|

<%=categories[i].title%>


55|

Cannot read property 'slug' of undefined
at eval (eval at compile (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:633:12), :109:39)
at returnedFn (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:668:17)
at tryHandleCache (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:254:36)
at View.exports.renderFile [as engine] (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:485:10)
at View.render (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\application.js:640:10)
at Function.render (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\response.js:1008:7)
at C:\Users\vaish\bestbags-nodejs-ecommerce\routes\index.js:20:9
at processTicksAndRejections (internal/process/task_queues.js:97:5)

Routing to app.js file

Hi! @maryamaljanabi I want to do routing operation inside pages.js to app.js=>
routing

but in app.js I cant use products it returns me this error
error

How can I fix it? is it possible to route app.js?

The index path corresponding to the specified order-by item is excluded

Hi, so I connected the app to azure cosmos DB NodeJS API. AdminBro works alright but I whenever I try to access the front page I get the following error.

GET / 302 685.380 ms - 46
MongoError: Error=2, Details='Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 77760ca9-a44a-49d1-93fc-c61413d5c5df; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 77760ca9-a44a-49d1-93fc-c61413d5c5df; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 77760ca9-a44a-49d1-93fc-c61413d5c5df; Reason: (Message: {"Errors":["The index path corresponding to the specified order-by item is excluded."]}
ActivityId: 77760ca9-a44a-49d1-93fc-c61413d5c5df, Request URI: /apps/a4038f59-dbab-454f-982e-c3c4ff0515f8/services/302463b7-7d21-4aa9-8c6a-1e7f8bc1c398/partitions/53e82a5d-f5cc-472f-83ae-6e4712cf3538/replicas/132878310044987400s/, RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, SDK: Windows/10.0.19041 cosmos-netstandard-sdk/3.18.0);););
at MessageStream.messageHandler (C:\node-js-projects\farmtopot\node_modules\mongodb\lib\cmap\connection.js:299:20)
at MessageStream.emit (node:events:390:28)
at processIncomingData (C:\node-js-projects\farmtopot\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (C:\node-js-projects\farmtopot\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at MessageStream.Writable.write (node:internal/streams/writable:334:10)
at TLSSocket.ondata (node:internal/streams/readable:754:22)
at TLSSocket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23) {
ok: 0,
code: 2,
codeName: 'BadValue'
}
GET / 302 630.101 ms - 46

Security Solution

Hi, thanks for sharing the source code. I can see a CSRF prevention set up for this, so do you use any other security solutions? Thanks.

Schemas missing "_id" field - Readme.md

The schemas have a good representation, but the "_id" field isn't there(I know that "_id" field is automatically created by MongoDB ). It is important to have a full description of your schemas even if the field it's not fully explicit, in case anyone wants to have an overview about the project.

Mongodb connect issue

Can you please provide a bit brief on how to create .env file and connect mongo db.. if there is any sample.

Mongo DB URI Credentials

Hi

How do i provide credentials in the .env file as my Mongo DB requires Authentication

Regards

Date format

Hi! @maryamaljanabi I want to change dateformat as 'yyyy/mm/dd' but I couldnt find where I have to do this changing. Could you help me please!

Secret option issue

Hi! when I start the app with npm start it returns me that and not upload the website

express-session deprecated undefined resave option; provide resave option node_modules\admin-bro-expressjs\plugin.js:176:14
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option node_modules\admin-bro-expressjs\plugin.js:176:14
express-session deprecated req.secret; provide secret option node_modules\admin-bro-expressjs\plugin.js:176:14
express-session deprecated req.secret; provide secret option app.js:34:3

how can I fix it?

sign in problem

Hi! @maryamaljanabi I can sign up succesfully but after sign in ,right up corner Icant see user name and cant add product to cart one more thing when I try to sign in I tried wrong email and password it dont show error messages
Thanks for help!

Replacing Products

I've been playing around with this for a few days now, I was wondering how I would go about removing faker and replacing with real products to down the line have on a live site.

Installation Guide

Hi,
I check this eCommerce code but here some issues coming so you need to describe proper installation guide also so that anybody can setup it on his local system easily and can contribute for this code.
Thanks

i have a issue when access link heroku of your

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

cant find

hi , please help to me to fix
image
i cant fix this were i should give , i have done my try

notice module

Hi @maryamaljanabi I created a notice module for carousel, first created model file and then created notices.js in routes directory I want to use variable that returns from notices.js file in home.ejs but it returns me error when I use variable
here is my code and error message thanks for help

homeejs
error
routes

I cant able to fill MongoDB Atlas database.

I cant able to fill the MongoDB database that you have mentioned to do "you need to navigate to the "seedDB" folder and run "node category-seed.js" and "node products-seed.js" " .
It is showing like this error

image

Cannot read property 'slug' of undefined

I'm getting this error in home.ejs. How can I solve it?

TypeError: C:\Users\vaish\bestbags-nodejs-ecommerce\views\shop\home.ejs:52
    50|     <% for(let i=0; i<3; i++){ %>
    51|     <div class="col-lg-3 col-md-3 col-sm-12 text-center ml-2">
 >> 52|       <a class="title-link" href="/products/<%=categories[i].slug%>">
    53|         <img src="images/dept<%=i%>.jpg" alt="category" class="circle-img" />
    54|         <h4 class="mb-3 mt-3"><%=categories[i].title%></h4>
    55|       </a>

Cannot read property 'slug' of undefined
    at eval (eval at compile (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:633:12), <anonymous>:109:39)
    at returnedFn (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:668:17)
    at tryHandleCache (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:254:36)
    at View.exports.renderFile [as engine] (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\ejs\lib\ejs.js:485:10)
    at View.render (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\view.js:135:8)
    at tryRender (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\application.js:640:10)
    at Function.render (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (C:\Users\vaish\bestbags-nodejs-ecommerce\node_modules\express\lib\response.js:1008:7)
    at C:\Users\vaish\bestbags-nodejs-ecommerce\routes\index.js:20:9
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Add SECURITY.md

Hey there!

I belong to an open source security research community, and a member (@ktg9) has found an issue, but doesn’t know the best way to disclose it.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

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.