O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MEAN Web Development - Second Edition

Book Description

Develop your real-time MEAN application efficiently using a combination of MongoDB, Express, Angular, and Node

About This Book

  • Construct a fully-functional MEAN application by using its components along with the best third-party modules
  • Harness the power of the JavaScript ecosystem to effectively run, build, and test your MEAN application
  • Gain a deep, practical understanding of real-time web application development through real-world examples

Who This Book Is For

If you are a JavaScript developer who is interested in building modern web applications using MongoDB, Express, Angular 2, and Node 5.0, then this book is for you. You only need knowledge of JavaScript development.

What You Will Learn

  • Use MongoDB to store and retrieve your application's data
  • Connect your Express application to MongoDB and use the Mongoose module
  • Manage your users' authentication and offer them diverse login options using Passport
  • Structure and use an Angular 2 application in your MEAN project
  • Use Socket.io to create real-time communication between your client and server
  • Test your application's Express and Angular 2 entities

In Detail

The MEAN stack is a collection of the most popular modern tools for web development that helps you build fast, robust, and maintainable web applications.

Starting with the MEAN core frameworks, this pragmatic guide will explain the key concepts of each framework, how to set them up properly, and how to use popular modules to connect it all together. By following the real-world examples shown in this tutorial, you will scaffold your MEAN application architecture, add an authentication layer, and develop an MVC structure to support your project development. You will learn the best practices of maintaining clear and simple code and will see how to avoid common pitfalls. Finally, you will walk through the different tools and frameworks that will help expedite your daily development cycles.

Watch how your application development grows by learning from the only guide that is solely orientated towards building a full, end-to-end, real-time application using the MEAN stack!

Style and approach

This comprehensive guide covers every part of the MEAN stack, and focuses on the gestalt power of the apps they can create through practical, real-world examples

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 http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. MEAN Web Development Second Edition
    1. Table of Contents
    2. MEAN Web Development Second Edition
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    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. Introduction to MEAN
      1. Three-tier web application development
      2. The evolution of JavaScript
      3. Introduction to ECMAScript 2015
        1. Modules
        2. Classes
        3. Arrow functions
        4. Let and Const
        5. Default, Rest, and Spread
        6. Summary
      4. Introducing MEAN
      5. Installing MongoDB
        1. Installing MongoDB on Windows
          1. Running MongoDB manually
          2. Running MongoDB as a Windows service
        2. Installing MongoDB on Mac OS X and Linux
        3. Installing MongoDB from binaries
          1. Installing MongoDB using a package manager
        4. Using the MongoDB shell
      6. Installing Node.js
        1. Installing Node.js on Windows
        2. Installing Node.js on Mac OS X
        3. Installing Node.js on Linux
        4. Running Node.js
      7. Introducing npm
        1. Using npm
          1. The installation process of npm
            1. Installing a package using npm
            2. Removing a package using npm
            3. Updating a package using npm
          2. Managing dependencies using the package.json file
            1. Creating a package.json file
            2. Installing the package.json dependencies
            3. Updating the package.json file
      8. Summary
    9. 2. Getting Started with Node.js
      1. Introduction to Node.js
        1. io.js and the Node.js foundation
        2. Node.js ES6 support
        3. Node.js LTS support
        4. JavaScript event-driven programming
        5. Node.js event-driven programming
      2. JavaScript Closures
      3. Node modules
        1. CommonJS modules
        2. Node.js core modules
        3. Node.js third-party modules
        4. Node.js file modules
        5. Node.js folder modules
      4. Developing Node.js web applications
        1. Meet the Connect module
          1. Connect middleware
          2. Understanding the order of Connect middleware
          3. Mounting Connect middleware
      5. Summary
    10. 3. Building an Express Web Application
      1. Introducing Express
      2. Installing Express
      3. Creating your first Express application
      4. The application, request, and response objects
        1. The application object
        2. The request object
        3. The response object
      5. External middleware
      6. Implementing the MVC pattern
        1. The application folder structure
          1. Horizontal folder structure
          2. Vertical folder structure
          3. File-naming conventions
          4. Implementing the horizontal folder structure
            1. Handling request routing
            2. Adding the routing file
      7. Configuring an Express application
        1. Environment configuration files
      8. Rendering views
        1. Configuring the view system
        2. Rendering EJS views
      9. Serving static files
      10. Configuring sessions
      11. Summary
    11. 4. Introduction to MongoDB
      1. Introduction to NoSQL
      2. Introducing MongoDB
      3. Key features of MongoDB
        1. The BSON format
        2. MongoDB ad hoc queries
        3. MongoDB indexing
        4. MongoDB replica set
        5. MongoDB sharding
        6. MongoDB 3.0
      4. MongoDB shell
      5. MongoDB databases
      6. MongoDB collections
      7. MongoDB CRUD operations
        1. Creating a new document
          1. Creating a document using insert()
          2. Creating a document using update()
          3. Creating a document using save()
        2. Reading documents
          1. Finding all the collection documents
          2. Using an equality statement
          3. Using query operators
          4. Building AND/OR queries
        3. Updating existing documents
          1. Updating documents using update()
          2. Updating documents using save()
        4. Deleting documents
          1. Deleting all documents
            1. Deleting multiple documents
            2. Deleting a single document
      8. Summary
    12. 5. Introduction to Mongoose
      1. Introducing Mongoose
        1. Installing Mongoose
        2. Connecting to MongoDB
      2. Understanding Mongoose schemas
        1. Creating the user schema and model
        2. Registering the User model
        3. Creating new users using save()
        4. Finding multiple user documents using find()
          1. Advanced querying using find()
        5. Reading a single user document using findOne()
        6. Updating an existing user document
        7. Deleting an existing user document
      3. Extending your Mongoose schema
        1. Defining default values
        2. Using schema modifiers
          1. Predefined modifiers
          2. Custom setter modifiers
          3. Custom getter modifiers
        3. Adding virtual attributes
        4. Optimizing queries using indexes
      4. Defining custom model methods
        1. Defining custom static methods
        2. Defining custom instance methods
      5. Model validation
        1. Predefined validators
        2. Custom validators
      6. Using Mongoose middleware
        1. Using pre middleware
        2. Using post middleware
      7. Using Mongoose ref fields
      8. Summary
    13. 6. Managing User Authentication Using Passport
      1. Introducing Passport
        1. Installing Passport
        2. Configuring Passport
      2. Understanding Passport strategies
        1. Using Passport's local strategy
          1. Installing Passport's local strategy module
          2. Configuring Passport's local strategy
        2. Adapting the User model
        3. Creating the authentication views
        4. Modifying the Users controller
          1. Displaying flash error messages
            1. Installing the Connect-Flash module
            2. Configuring Connect-Flash module
            3. Using Connect-Flash module
        5. Wiring the user's routes
      3. Understanding Passport OAuth strategies
        1. Setting up OAuth strategies
          1. Handling OAuth user creation
          2. Using Passport's Facebook strategy
            1. Installing Passport's Facebook strategy
            2. Configuring Passport's Facebook strategy
            3. Wiring Passport's Facebook strategy routes
          3. Using Passport's Twitter strategy
            1. Installing Passport's Twitter strategy
            2. Configuring Passport's Twitter strategy
            3. Wiring Passport's Twitter strategy routes
          4. Using Passport's Google strategy
            1. Installing Passport's Google strategy
            2. Configuring Passport's Google strategy
            3. Wiring Passport's Google strategy routes
      4. Summary
    14. 7. Introduction to Angular
      1. Introducing Angular 2
        1. From Angular 1.x to Angular 2.x
      2. Introduction to TypeScript
        1. Types
          1. Basic types
          2. The any type
        2. Interfaces
        3. Decorators
          1. Summary
      3. Angular 2 Architecture
        1. Angular 2 Modules
        2. Angular 2 Components
        3. Angular 2 Templates
        4. Angular 2 data binding
          1. Interpolation binding
          2. Property binding
          3. Event binding
          4. Two-way binding
        5. Angular 2 Directives
          1. Attribute directives
          2. Structural directives
          3. Component directives
        6. Angular 2 Services
        7. Angular 2 Dependency Injection
          1. Using Dependency Injection in Angular 2
        8. Angular 2 Routing
          1. Setup
          2. Routes
          3. Router outlet
          4. Router links
          5. Summary
      4. The project setup
        1. Configuring TypeScript
        2. Configuring Express
        3. Restructuring the application
        4. Creating the application module
        5. Creating the application component
        6. Bootstrapping the application module
        7. Starting your Angular application
      5. Managing authentication
        1. Rendering the user object
        2. Modifying the users' server controller
        3. Creating the authentication module
          1. Creating the authentication component
          2. Configuring the authentication routes
          3. Creating the signin component
          4. Creating the signup component
          5. Creating the authentication service
        4. Creating the home module
          1. Creating the home component
          2. Configuring the home routes
        5. Refactoring the application module
          1. Configuring the application routes
      6. Summary
    15. 8. Creating a MEAN CRUD Module
      1. Introducing CRUD modules
      2. Setting up the Express components
        1. Creating the Mongoose model
        2. Setting up the Express controller
          1. The error handling method of the Express controller
          2. The create() method of the Express controller
          3. The list() method of the Express controller
          4. The read() middleware of the Express controller
          5. The update() method of the Express controller
          6. The delete() method of the Express controller
          7. Implementing an authentication middleware
          8. Implementing an authorization middleware
        3. Wiring the Express routes
        4. Configuring the Express application
      3. Using the HTTP client
        1. Reactive programming and Observables
      4. The ReactiveX library
        1. Using the http client
      5. Implementing the Angular module
        1. Creating the Angular module service
        2. Implementing the Create subcomponent
          1. Adding the template
        3. Implementing the View subcomponent
          1. Adding the template
        4. Implementing the Edit subcomponent
          1. Adding the template
        5. Implementing the List subcomponent
          1. Adding the template
      6. Wrapping up
      7. Summary
    16. 9. Adding Real-time Functionality Using Socket.io
      1. Introducing WebSockets
      2. Introducing Socket.io
        1. The Socket.io server object
          1. Socket.io handshaking
          2. The Socket.io configuration middleware
        2. The Socket.io client object
        3. Socket.io events
          1. Handling events
          2. Emitting events
        4. Socket.io namespaces
          1. Socket.io server namespaces
          2. Socket.io client namespaces
        5. Socket.io rooms
          1. Joining and leaving rooms
          2. Emitting events to rooms
      3. Installing Socket.io
        1. Configuring the Socket.io server
        2. Configuring the Socket.io session
          1. Installing the connect-mongo and cookie-parser modules
          2. Configuring the connect-mongo module
          3. Configuring the Socket.io session
      4. Building a Socket.io chat
        1. Setting the event handlers of the chat server
      5. Creating the Chat Angular module
        1. Setting up the Socket.io client library
        2. Creating the Chat module
        3. Creating the Chat service
        4. Creating the Chat component
        5. Creating the Chat template
        6. Adding the Chat routing configuration
        7. Using the Chat module
      6. Summary
    17. 10. Testing MEAN Applications
      1. Introducing JavaScript testing
        1. TDD, BDD, and unit testing
        2. Test frameworks
        3. Assertion libraries
        4. Test runners
      2. Testing your Express application
        1. Introducing Mocha
        2. Introducing Should.js
        3. Introducing SuperTest
      3. Installing Mocha
        1. Installing the Should.js and SuperTest modules
        2. Configuring your test environment
        3. Writing your first Mocha test
          1. Testing the Express model
          2. Testing the Express controller
        4. Running your Mocha test
      4. Testing your Angular application
        1. Introducing the Jasmine framework
        2. Angular unit tests
          1. Introducing Karma test runner
          2. Installing the Karma command-line tool
          3. Installing Karma's dependencies
          4. Configuring the Karma test runner
          5. Writing Angular unit tests
            1. Testing components
            2. Mocking backend data
            3. Testing services
            4. Testing routes
            5. Testing directives
            6. Testing pipes
          6. Running your Angular unit tests
        3. Angular E2E tests
          1. Introducing the Protractor test runner
          2. Installing the Protractor test runner
          3. Configuring the Protractor test runner
          4. Writing your first E2E test
          5. Running your Angular E2E tests
      5. Summary
    18. 11. Automating and Debugging MEAN Applications
      1. Using NPM scripts
      2. Introducing Webpack
        1. Installing Webpack
        2. Configuring Webpack
      3. Introducing ESLint
        1. Installing ESLint
        2. Configuring ESLint
      4. Using Nodemon
      5. Debugging Express with V8 inspector
      6. Debugging your application
      7. Debugging Angular applications with Angular Augury
        1. Using Angular Augury
        2. The component tree
        3. Router tree
      8. Summary
    19. Index