Code Monkey home page Code Monkey logo

meanshop's Introduction

Meanshop Build Status

E-commerce Application built with the MEAN stack

This e-commerce platform is built step-by-step on my book "Building an e-Commerce Application with MEAN" available on:

Building an e-Commerce Application with MEAN

Table of Contents

Installation

The following instructions are the most common to get the development environment up and running. If you run into issues, check out the troubleshooting section and alternative OS-independent installations using Docker.

Node v0.12.x

This installation covers *nix like systems (OS X and Ubuntu/Linux). Windows? check out https://github.com/coreybutler/nvm-windows

You need Node 0.12 in your system. Verify if you already have it with node -v. If not or a different version, you can use Node Version Manager (nvm) to install it:

curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash
source ~/.nvm/nvm.sh
nvm install 0.12
nvm use 0.12

NPM global dependencies

# Bower
npm install -g bower

# Grunt CLI
npm install -g grunt-cli

# Yeaoman
npm install -g yo

# Angular fullstack generators
npm install -g [email protected]

Sass dependencies

You need to have ruby in your system. Mac OS X and Linux ship with Ruby, verify by typing ruby -v. Windows: if you are using windows install Ruby with http://rubyinstaller.org/downloads/

Then, install the sass gem (library):

gem install sass

MongoDB v3.x

  • Mac: brew install mongodb 3.0.2
  • Ubuntu: sudo apt-get -y install mongodb=3.0.2

Source code

You can either build the project from scratch following the instructions on the book's chapter 1 or get the source code.

git clone https://github.com/amejiarosario/meanshop.git
cd meanshop
npm install
bower install

Getting a chapter's code

By default when you checkout, you get the master branch which is the latests version of the app. For your convenience, you can also checkout chapter's code with the following commands (inside the project directory):

# checking out chapter 1
git checkout ch1

# checking out chapter 7
git checkout ch7

# checking out the latest
git checkout master

Usage

  • run server (dev mode): grunt serve
  • run server (production mode): grunt serve:dist
  • run tests: grunt test
  • run e2e tests: grunt test:e2e
  • compile assets: grunt build

Setting up 3rd party Integrations

You need 3rd party API credentials to be able to use the application. They are stored in the local.env.js, but since it will contain sensitive information you need to create it yourself. Use the sample file local.env.sample.js to make a copy of a real one:

cp server/config/local.env.sample.js server/config/local.env.js

Get Braintree keys from: https:// www.braintreepayments.com/get-started. Check book chapter 7 for more details.

  BRAINTREE_ID: 'public key',
  BRAINTREE_SECRET: 'private key',
  BRAINTREE_MERCHANT: 'merchant ID',

Note: Everytime a keys is added you need to stop grunt serve and start it again.

Using the Braintree sandbox account

We can test the workflow of order creation by running the application:

  1. Add multiple products to the shopping cart.
  2. Checkout the products using some valid credit card numbers for testing such as 4111 1111 1111 1111 or 4242 4242 4242 4242.
  3. Any expiration date in the future will do.

Optional for social Login

In the chapter 6 you can find more detailed information. Here's a summary of what you need:

Go to Facebook Developers and register your app: https://developers.facebook.com

  FACEBOOK_ID:      'app-id',
  FACEBOOK_SECRET:  'secret',

Go to Twitter Apps and get your app registred: https://apps.twitter.com

  TWITTER_ID:       'app-id',
  TWITTER_SECRET:   'secret',

Go to Google Developers and get the credentials: https://console.developers.google.com/project

  GOOGLE_ID:        'app-id',
  GOOGLE_SECRET:    'secret',

Issues

For any question, ideas for improvement use click here.

Contributing

If you have ideas to make this app better (and you should! ๐Ÿ˜‰) you can contribute your features using the following instructions:

  1. Fork it clicking the fork button on the top right corner of this page.
  2. Create your feature branch: git checkout -b my-new-feature.
  3. Commit your changes: git add . && git commit -m 'Add some feature'.
  4. Push to the branch: git push origin my-new-feature
  5. Come to this page and it will show up "create pull request" option.
  6. Submit your pull request and add some info about your changes. Include screenshots and animated GIFs in your pull request whenever possible.

When you are contributing for a 2nd time or further, sync your fork to make sure you have the latest code. More instructions in setting upstream and syncing a fork.

Deploying to Heroku

Heroku requires installing a command-line program called heroku-toolbelt. Follow the instructions on https://toolbelt.heroku.com to install it. Also, create an account in Heroku if haven't yet.

Deploy commands:

# Build for production
grunt build

# Use angular generator to deploy
yo angular-fullstack:heroku

# Add MongoDB to heroku deployment
cd dist && heroku addons:create mongolab:sandbox

# Set environment to production
heroku config:set NODE_ENV=production

# Add all 3rd party credentials .e.g.:
$ heroku config:set FACEBOOK_ID=appId FACEBOOK_SECRET=secret

# See deployed app
heroku open

You can visualize all the set variables with heroku config.

Any other update can be refreshed on Heroku by typing the following command: grunt buildcontrol:heroku.

Troubleshooting

Depending on the OS, there are some subtle differences.

If you don't have enough permissions consider using: sudo npm install vs npm install

Allows running commands as root: bower install --allow-root

Detailed MongoDB installation on Ubuntu:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.0.2 mongodb-org-server=3.0.2 mongodb-org-shell=3.0.2 mongodb-org-mongos=3.0.2 mongodb-org-tools=3.0.2

Docker

Docker allows to run app independently from OS. It works for Windows, Mac, Linux and most cloud providers (AWS, Digital Ocean, ...). Just need to install docker from https://www.docker.com/.

After installing docker programs, go to the terminal:

# make sure you have them available
docker --version
docker-compose --version

# start docker daemons
docker-machine ls
docker-machine start default
eval "$(docker-machine env default)"

# create VMs (might take a while the first time since installs all NPM packages)
docker-compose build

# run the app
docker-compose up -d

# get ip of the VM
docker-machine ip

# open browser with running app on http://192.168.99.100:7000
open http://$(docker-machine ip):7000 # only OS X

# List containers
docker-compose ps

#      Name               Command          State            Ports
#      -------------------------------------------------------------------------
#      meanshop_db_1    /entrypoint.sh mongod   Up      0.0.0.0:27017->27017/tcp
#      meanshop_web_1   npm start               Up      0.0.0.0:7000->7000/tcp

# Run commands in containers (e.g. database container)
docker exec -it meanshop_db_1 bash

#=>     root@834d77cc6b36:/# mongo
#=>     MongoDB shell version: 3.2.6
#=>     connecting to: test
#=>     Welcome to the MongoDB shell.
#=>     
#=>     > show dbs
#=>     local         0.000GB
#=>     meanshop      0.000GB
#=>     meanshop-dev  0.000GB
#=>     
#=>     > use meanshop-dev
#=>     switched to db meanshop-dev
#=>     
#=>     > show collections
#=>     catalogs
#=>     products
#=>     sessions
#=>     users
#=>
#=>     > db.products.find({})
#=>     { "_id" : ObjectId("573204ad48b9ba0c001eea3b"), "title" : "MEAN eCommerce Book", "imageUrl" : "/assets/uploads/meanbook.jpg", "price" : 25, "description" : "Build a powerful e-commerce application quickly with MEAN, a leading full-JavaScript stack. It takes you step-by-step from creating a real-world store to managing details such as authentication, shopping carts, payment, scalability and more.", "categories" : [ ObjectId("573204ad48b9ba0c001eea39") ], "stock" : 250, "__v" : 0 }
#=>     { "_id" : ObjectId("573204ad48b9ba0c001eea3c"), "title" : "T-shirt", "imageUrl" : "/assets/uploads/meantshirt.jpg", "price" : 15, "description" : "T-shirt with the MEAN stack logo", "categories" : [ ObjectId("573204ad48b9ba0c001eea3a") ], "stock" : 100, "__v" : 0 }
#=>     { "_id" : ObjectId("573204ad48b9ba0c001eea3d"), "title" : "Coffee Mug", "imageUrl" : "/assets/uploads/meanmug.jpg", "price" : 8, "description" : "Convert coffee into MEAN code", "categories" : [ ObjectId("573204ad48b9ba0c001eea38") ], "stock" : 50, "__v" : 0 }


# View logs
docker-compose logs # or docker-compose logs web # or docker-compose logs db

# Stop services
docker-compose stop

# Remove stopped containers
docker-compose rm

Contact

Find my contact info at http://adrianmejia.com.

meanshop's People

Contributors

amejiarosario avatar cosjef avatar poissonj 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meanshop's Issues

Quantity per Variant

Inventory support by product variant. E.g. sizes (S, M, L) and colors (black, white, blue, green)

braintree clientToken issue

When running the application and accessing the "checkout" page I receive this error:

/server/api/braintree/braintree.controller.js:33
return handleResponse(res)(err, data.clientToken);
^
TypeError: Cannot read property 'clientToken' of null
at /Applications/Sites/Tutorials/meanshop-book/server/api/braintree/braintree.controller.js:33:41
at /Applications/Sites/Tutorials/meanshop-book/node_modules/braintree/lib/braintree/client_token_gateway.js:68:16
at IncomingMessage. (/Applications/Sites/Tutorials/meanshop-book/node_modules/braintree/lib/braintree/http.js:99:18)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at doNTCallback2 (node.js:452:9)
at process._tickCallback (node.js:366:17)

Can't upload picture when creating new product

Steps to reproduce

  1. Login
  2. /products/new
  3. Add new product data
  4. Upload a picture
  • Notice that the picture doesn't get saved.

Workarounds

  • Create new product without picture
  • Then click edit and upload a picture. It will works this time

some duplicated code

catalog.events.js is identical to product.events.js (just changing the variable names).
same for catalog.socket.js and product.sockets.js.
and a big part also for catalog.controller.js and product.controller.js.

how would you best remove such duplication?

i18n and l10n

Internationalization and localization to translate and localize all content for the world.

fix installation instructions of the first chapter of the book

Following the instructions of the first chapter of the associated book, results in several errors:

It's missing at page 6:
$ npm install -g yo

It's missing at page 8:

$ npm install -g grunt-cli
# Install dependencies for grunt-contrib-sass. Instructions: https://github.com/gruntjs/grunt-contrib-sass
$ npm install -g bower
$ bower install

I didn't find a place in the oreilly website to provide feedback about your book. should I write here comments about the book, or somewhere else?

Setup instructions

Update the README with:

  • Instructions to launch the application
  • Instructions (for non-programmers) to make it easy to deploy their own e-commerce platforms.
  • Run tests and shop locally.

Unable to update the image

Hello I bought his book very interesting, but there is a problem in the upload image.
I created a new product, I go to edit upload the image and save the product, but then it is impossible to change the image.
Debugging the application I noticed that, when I get another picture, uploadHander updates the DB, but then when saved, the DB is again updated with the previous image

webserver is down for a bug in one request?

I checkout this meanshop repository and I forget to configure the braintree payment. I run the server with grunt serve, and I can browse successfully the pages about catalog. If I click on the cart, then there is a server error:

/Users/david/webdev/meanshop/server/api/braintree/braintree.controller.js:33
    return handleResponse(res)(err, data.clientToken);
                                        ^
TypeError: Cannot read property 'clientToken' of null
    at /Users/david/webdev/meanshop/server/api/braintree/braintree.controller.js:33:41

and now all the webserver is down; I cannot browse the pages about catalog as before.

only because of a bug in one page, the whole webserver is now down.
I think this is not acceptable.
what do you think?

why you use objects with only one field, when you could use a simple data type?

Is there any reason why in chapter 2, the get function of the product service takes an object params (with only one field id) as a parameter, instead of just a simple parameter productId?

you have:

https://github.com/amejiarosario/meanshop/blob/ch2/client/app/products/products.service.js
      get: function(params){
          if(product._id == params.id){

https://github.com/amejiarosario/meanshop/blob/ch2/client/app/products/products.controller.js
    $scope.product = Product.get({id: $stateParams.id});

why not simply?

https://github.com/amejiarosario/meanshop/blob/ch2/client/app/products/products.service.js
      get: function(productId){
          if(product._id == productId){

https://github.com/amejiarosario/meanshop/blob/ch2/client/app/products/products.controller.js
    $scope.product = Product.get($stateParams.id);

Docker Ready

Build, ship and run Reaction containers anywhere.

the dist client code size is huge

running grunt build creates the dist folder, with all the client scripts and css concatenated and minified. These are the files:

 28Kb app.2478a1c2.js
129Kb app.79e4c1fe.css
641Kb vendor.9531310c.js
  0Kb vendor.d41d8cd9.css

the web browser needs to download almost 1Mb before seeing anything. I hated this type of web applications when I was traveling in Asia with a slow internet connection. Is there a solution for this?

Also, in the dist directory:

dist/Procfile
dist/client/app
dist/client/assets
dist/client/bower_components
dist/client/favicon.ico
dist/client/index.html
dist/client/robots.txt
dist/package.json
dist/server/...

there is client/bower_components/ (9.7Mb)
I tried deleting this folder, and the application runs ok.
Is this directory really needed?
or everything needed here is already compiled in the client/app/vendor.9531310c.js?
if it can be deleted, why does grunt build not clean it?

This is a question, not an issue. Where should I post questions?

how to run your source code files locally

how to run your source file downloaded from packtpub. I teid npm install and bower install in project folder of each chapter. then executed grunt serve.
Getting error on npm install.

not able to find any css documents on any page...

Error on npm install:
node-pre-gyp install --fallback-to-build

Using Ubuntu 15.04

homepage works fine but it show no css.

The entire error log -
npm WARN EPEERINVALID [email protected] requires a peer of kerberos@~0.0 but none was installed.
npm WARN EPEERINVALID [email protected] requires a peer of phantomjs@>=1.9 but none was installed.
npm ERR! Linux 3.19.0-49-generic
npm ERR! argv "/home/alchemist/.nvm/versions/node/v5.0.0/bin/node" "/home/alchemist/.nvm/versions/node/v5.0.0/bin/npm" "install"
npm ERR! node v5.0.0
npm ERR! npm v3.3.6
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! This is most likely a problem with the v8-debug package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR! npm owner ls v8-debug
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/alchemist/meanshop/npm-debug.log

Real Time Reactive

Changes made to your shop are instantly seen by your shoppers (without page reloads).

Order history per user

For purchase history for each user: Use orders filtered by current user. Admin should be able to see everything.

ReferenceError: io is not defined

Deployment seemed to work without a hitch, however the client side is throwing this breaking error:
"ReferenceError: io is not defined"

Any help would be great!

2.x

Let's get started on the next generation. I have a few forks of this repo I just synchronized, I am leaving this one vanilla (with your default theme and products) here

But things are pretty messy in there so rather than pull all that crap back into your repo, perhaps we can make a few tasks and hopefully I can help out as I went through the process of upgrading things for boron (at first I was using the latest 7.x, but quickly realized my hubris).

Perhaps we could use something like waffle to plan things out?

@amejiarosario Thanks for the project! I hope to contribute back something in return.

npm dependencies

in the book, Chapter1, "Installing the MEAN component":
you explain to install several dependencies.

these ones, you install them globally. I understand, because when someone clones your already-inplemented project, he does not need those, as they are used to create the scaffolder.
npm install -g yo
npm install -g generator-angular-fullstack

however, you install these two globally, and they are needed for development. so, if someone clones your project, he will fail to build/run it without them. Why you don't install them locally with --save-dev?
npm install -g grunt-cli
npm install -g bower

and this one, you install it globally, but it is used in production. so why not install it locally with --save?
npm install -g express

npm ERR!

Hello,

I just cloned the folder, and did npm install, it returns errors:

npm WARN [email protected] requires a peer of kerberos@~0.0 but none was installed.
npm WARN [email protected] requires a peer of phantomjs@>=1.9 but none was installed.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/bufferutil):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/utf-8-validate):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm ERR! Darwin 16.3.0
npm ERR! argv "/usr/local/Cellar/node/7.2.1/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.2.1
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the v8-debug package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs v8-debug
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls v8-debug
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/chengtie/Desktop/meanshop/npm-debug.log

Could anyone tell me what's wrong here?

Cheers

Tie

production build

Hi,

I followed you book and was able to create the app as expected. Now we are doing testing and many thanks to you & the book for helping me learn MEAN Stack. Now while i was deploying on UAT as build i am facing challenges as the build is not coming proper and its breaking. I have been trying for last 4 days but not able to make it working.

I am getting below message and it seems to be the cause.

Running "injector:scripts" (injector) task
Missing option 'template', using 'dest' as template instead
Injecting js files (30 files)

Running "injector:css" (injector) task
Missing option 'template', using 'dest' as template instead
Injecting css files (9 files)

Thanks in advance, any help will be highly appreciated.

Shipping

  • Allow the shop to capture shipping/billing address for physical goods.
  • Optional shipping for digital goods (eBooks, audio, videos)

this.$index

in chapter 10 "Planning a new feature", you have this sample:

at admin.controller.js, you have:

    $scope.deleteUser = function(user) {
      User.remove({ id: user._id });
      $scope.users.splice(this.$index, 1);
    };

and admin.html

      <tr ng-repeat="user in users">
          <a ng-click="deleteUser(user)"><i class="fa fa-2x fa-trash-o"></i></a>
      </tr>

what is this here? it represents a context inside the repeat loop?
can you explain more about this.$index?

Error: No picture file

Hi Adrian... thank you for sharing your knowledge.

I tried to edit a product, and this product has a picture, but, I can not save without upload a new picture.

How I make this only when create a new product no in edition?

image

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.