You are previewing Building an E-Commerce Application with MEAN.
O'Reilly logo
Building an E-Commerce Application with MEAN

Book Description

Develop an end-to-end, real-time e-commerce application using the MEAN stack

About This Book

  • Build all the main components of an e-commerce website and extend its high-quality features as per your needs
  • Get to grips with the full-stack JavaScript to build attractive e-commerce sites and start making money
  • A step-by-step guide to developing the MEAN stack components from scratch to achieve maximum flexibility when building an e-commerce application

Who This Book Is For

This book is for a web or full stack JavaScript developer who wants to get a head start on developing an e-commerce application with MEAN. A basic knowledge of the MEAN stack is highly recommended.

What You Will Learn

  • Employ AngularJS to build responsive UI components
  • Implement multiple authentication strategies such as OAuth, JsonWebToken, and Sessions
  • Enhance website usability with social logins such as Facebook, Twitter, and Google
  • Create integrations with payment platforms such as PayPal
  • Apply full-text search functionality in MongoDB
  • Build a flexible categorization system to organize your products
  • Secure your app by creating SSL certificates and run payment platforms in a live environment

In Detail

MEAN stands for MongoDB, Express, AngularJS, and Node.js. It is a combination of a NoSQL database, MongoDB, with a couple of JavaScript web application frameworks, namely Express.js and Angular.js. These run on Node.js.

There is always an ever-growing list of requirements while designing an e-commerce application, which needs to be flexible enough for easy adaptation. The MEAN stack allows you to meet those requirements on time and build responsive applications using JavaScript.

This book will show you how to create your own e-commerce application using the MEAN stack. It will take you step by step through the parallel process of learning and building. It will also teach you to develop a production-ready, high-quality e-commerce site from scratch and will provide the knowledge you need to extend your own features to the e-commerce site.

This book starts with a short introduction to the MEAN stack, followed by a step-by-step guide on how to build a store with AngularJS, set up a database with MongoDB, create a REST API, and wire AngularJS. It also shows you how to manage user authentication and authorization, check multiple payment platforms, add products’ search and navigation, deploy a production-ready e-commerce site, and finally add your own high-quality feature to the site.

By the end of the book, you will be able to build and use your own e-commerce app in the real world and will also be able to add your own new features to it.

Style and approach

This book is a step-by-step guide on how to build a real-time e-commerce app with MEAN. Each transition is well explained, and each chapter begins with the required background knowledge.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

Table of Contents

  1. Building an E-Commerce Application with MEAN
    1. Table of Contents
    2. Building an E-Commerce Application with MEAN
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Getting Started with the MEAN Stack
      1. Introducing the MEAN stack
        1. NodeJS
        2. ExpressJS
        3. MongoDB
        4. AngularJS
      2. Installing the MEAN component
        1. Installing NodeJS
        2. Installing ExpressJS
        3. Installing MongoDB
        4. Installing AngularJS tools
        5. The AngularJS debugger
      3. Understanding the project structure
        1. The file structure
        2. Components
          1. Testing
          2. Tools
          3. Package managers
          4. Bower packages
      4. Previewing the final e-commerce app
        1. Homepage
        2. Marketplace
        3. Backoffice
      5. Understanding the requirements for e-commerce applications
        1. Minimum Viable Product for an e-commerce site
        2. Defining the requirements
      6. Summary
    9. 2. Building an Amazing Store Frontend with AngularJS
      1. Understanding AngularJS and the client directory structure
        1. Client-side structure
        2. Directives
        3. Modules
        4. Routing with AngularUI router
        5. Controllers and scopes
        6. Templates
      2. Laying out the e-commerce MVP
        1. Products
        2. Factories and services
          1. Creating the products factory
        3. Creating the marketplace
        4. Filters
      3. CRUD-ing products with AngularJS
        1. Services
        2. Controllers
        3. Routes
        4. Templates
          1. Partial forms
          2. Product New
          3. Product edit
          4. The product view
          5. The product list
        5. Styling the main page
      4. Summary
    10. 3. Building a Flexible Database with MongoDB
      1. Understanding MongoDB
        1. MongoDB daemons and CLI
        2. Mapping SQL knowledge to MongoDB
          1. Basics concepts
          2. Queries
          3. Aggregators
      2. CRUDing with Mongoose
        1. Schemas
        2. Create
        3. Read
        4. Update
        5. Delete
      3. Exploring a few advanced features in Mongoose
        1. Instance methods
        2. The static methods
        3. Virtuals
        4. Validations
          1. Built-in validations
          2. Custom validations
        5. Middleware
      4. Reviewing models and server-side structure
        1. The server folder
        2. Current Mongoose models
        3. CommonJS Modules
        4. The user model
      5. Summary
    11. 4. Creating a RESTful API with NodeJS and ExpressJS
      1. Getting started with REST
      2. Scaffolding RESTful APIs
      3. Bootstrapping ExpressJS
      4. Understanding routes in ExpressJS
      5. Testing, TDD, BDD, and NodeJS
      6. Creating the product model
        1. Testing the products model
        2. Product model implementation
      7. Implementing the Product API
        1. Testing the API
          1. Index action tests
          2. Show action tests
          3. Creating action tests
          4. Deleting action tests
        2. Product controller
      8. Summary
    12. 5. Wiring AngularJS with ExpressJS REST API
      1. Implementing a RESTful product service
        1. Building the marketplace
      2. Wiring the product controller with new RESTful methods
      3. Uploading product images
        1. Uploading files in Angular
        2. Handling file upload on Node
        3. Seeding products
      4. Testing RESTful APIs in AngularJS
        1. Unit testing
          1. ngMock
          2. Setting up testing
        2. Understanding the Services tests
        3. Testing all $resource methods
        4. Testing the Product Controller
      5. End-to-end testing
        1. Cleaning the database on each e2e run
      6. Summary
    13. 6. Managing User Authentication and Authorization
      1. Getting started with authentication strategies
        1. Session-based authentication
        2. Token-based authentication – using JWT
        3. OAuth authentication
      2. Understanding client-side authentication
        1. Authentication management
        2. The signing up process
      3. Understanding server-side authentication
        1. Authentication with PassportJS
        2. Initializing PassportJS
        3. The user model
        4. Authentication strategies and routes
          1. Local authentication
        5. End-to-end tests for local authentication
      4. Authenticating with Facebook, Google, and Twitter
        1. Facebook
        2. Twitter
        3. Google
      5. Summary
    14. 7. Checking Out Products and Accepting Payment
      1. Setting up the shopping cart
        1. Installing ngCart
        2. Making use of ngCart directives
          1. Add/remove to cart
          2. The cart's summary
      2. The checkout page and Braintree integration
      3. Setting up Braintree endpoint and authentication
        1. The API keys
        2. Gateway
        3. Controller
        4. Router
      4. Creating an order
        1. Modifying the order model
        2. Testing the order model
        3. Using the sandbox account
      5. Summary
    15. 8. Adding Search and Navigation
      1. Adding search to the navigation bar
      2. Adding product categories
        1. Adding the sidebar
        2. Improving product models and controllers
        3. Catalog controller and routes
        4. The catalog model
        5. Seeding products and categories
      3. Implementing the search and navigation functionality
        1. Adding custom $resource methods
        2. Setting up routes and controllers
      4. Wrapping it up
        1. How navigation works on the client side
        2. How search works on the client side
      5. Summary
    16. 9. Deploying a Production-ready e-Commerce App
      1. Building for production
        1. Application environments
        2. Optimizations for production environments
      2. Scaling web applications
        1. Scaling out vertically – one server
        2. Scaling out horizontally – multiple servers
      3. Deploying the application to the cloud
        1. Platform as a Service
          1. Heroku
        2. Virtual Private Servers and Cloud Servers
          1. Digital Ocean
      4. Deploying applications in a multi-server environment
        1. Setting up the app server – NodeJS application
        2. Setting up web server – Nginx server
      5. Performing stress tests
        1. HTTP benchmarking tools
          1. ApacheBench
        2. Benchmarking Heroku deployment
        3. Benchmarking VPS multi-server deployment
      6. Production architecture for scaling NodeJS
        1. Phase 0 – one server
        2. Phase 1 – multiple application instances in one server
        3. Phase 2 – multiple servers
        4. Phase 3 – Micro-services
      7. Next steps on security
      8. Summary
    17. 10. Adding Your Own Features with High Quality
      1. Planning a new feature
        1. Wire framing
        2. Implementing the solution
          1. The HTML page
      2. Testing the new feature
        1. AngularJS testing
      3. Features backlog
      4. Deploying a new version of the app
        1. Zero-downtime deployments
        2. Setting up the zero-downtime production server
        3. Getting started with Capistrano
          1. Installing Capistrano
          2. Understanding Capistrano
        4. Preparing the server
          1. Setting up Capistrano variables
        5. Capistrano tasks
          1. Adding new tasks
          2. Preparing Nginx
          3. Load balancing
          4. Static file server
          5. WebSockets
      5. Summary
    18. Index