MEAN Web Development

Book description

Master real-time web application development using a mean combination of MongoDB, Express, AngularJS, and Node.js

In Detail

The MEAN stack is a collection of the most popular modern tools for web development; it comprises MongoDB, Express, AngularJS, and Node.js.

Starting with MEAN core frameworks, this project-based 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. 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!

What You Will Learn

  • Set up and run an Express application
  • 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 AngularJS application in your MEAN project
  • Use Socket.io to create real-time communication between your client and server
  • Test your application's Express and AngularJS entities
  • Develop your MEAN application more efficiently using popular third-party tools

Table of contents

  1. MEAN Web Development
    1. Table of Contents
    2. MEAN Web Development
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      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. Introduction to MEAN
      1. Three-tier web application development
      2. The evolution of JavaScript
      3. Introducing MEAN
      4. 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
          1. Installing MongoDB from binaries
          2. Install MongoDB using a package manager
        3. Using the MongoDB shell
      5. 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
      6. 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
      7. Summary
    9. 2. Getting Started with Node.js
      1. Introduction to Node.js
        1. JavaScript event-driven programming
        2. 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. Introduction to 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. 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
      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 DBRef
      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 user 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 AngularJS
      1. Introducing AngularJS
      2. Key concepts of AngularJS
        1. The core module of AngularJS
          1. The angular global object
        2. AngularJS modules
          1. Application modules
          2. External modules
          3. Third-party modules
        3. Two-way data binding
        4. Dependency injection
          1. Dependency injection in AngularJS
        5. AngularJS directives
          1. Core directives
          2. Custom directives
        6. Bootstrapping an AngularJS application
          1. Automatic bootstrap
          2. Manual bootstrap
      3. Installing AngularJS
        1. Meeting the Bower dependencies manager
        2. Configuring the Bower dependencies manager
        3. Installing AngularJS using Bower
        4. Configuring AngularJS
      4. Structuring an AngularJS application
      5. Bootstrapping your AngularJS application
      6. AngularJS MVC entities
        1. AngularJS views
        2. AngularJS controllers and scopes
      7. AngularJS routing
        1. Installing the ngRoute module
        2. Configuring the URL scheme
        3. AngularJS application routes
      8. AngularJS services
        1. AngularJS prebundled services
        2. Creating AngularJS services
        3. Using AngularJS services
      9. Managing AngularJS authentication
        1. Rendering the user object
        2. Adding the Authentication service
        3. Using the Authentication service
      10. 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. Introducing the ngResource module
        1. Installing the ngResource module
        2. Using the $resource service
      4. Implementing the AngularJS MVC module
        1. Creating the AngularJS module service
        2. Setting up the AngularJS module controller
          1. The create() method of the AngularJS controller
          2. The find() and findOne() methods of the AngularJS controller
          3. The update() method of the AngularJS controller
          4. The delete() method of the AngularJS controller
        3. Implementing the AngularJS module views
          1. The create-article view
          2. The view-article view
          3. The edit-article view
          4. The list-articles view
        4. Wiring the AngularJS module routes
      5. Finalizing your module implementation
      6. 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
        2. Creating the Socket service
        3. Creating the chat controller
        4. Creating the chat view
        5. Adding chat routes
        6. Finalizing the chat implementation
      5. 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
        4. Installing Mocha
        5. Installing the Should.js and SuperTest modules
        6. Configuring your test environment
        7. Writing your first Mocha test
          1. Testing the Express model
          2. Testing the Express controller
        8. Running your Mocha test
      3. Testing your AngularJS application
        1. Introducing the Jasmine framework
        2. AngularJS 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. Mocking AngularJS components
            1. Introducing ngMock
            2. Installing ngMock
          6. Writing AngularJS unit tests
            1. Testing modules
            2. Testing controllers
            3. Testing services
            4. Testing routes
            5. Testing directives
            6. Testing filters
          7. Writing your first unit test
          8. Running your AngularJS unit tests
        3. AngularJS 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 AngularJS E2E tests
      4. Summary
    18. 11. Automating and Debugging MEAN Applications
      1. Introducing the Grunt task runner
        1. Installing the Grunt task runner
        2. Configuring Grunt
          1. Running your application using Grunt
          2. Testing your application using Grunt
          3. Linting your application using Grunt
          4. Watching file changes using Grunt
      2. Debugging Express with node-inspector
        1. Installing node-inspector's grunt task
        2. Configuring node-inspector's grunt task
        3. Running the debug grunt task
      3. Debugging AngularJS with Batarang
        1. Using Batarang
          1. Batarang Models
          2. Batarang Performance
          3. Batarang Dependencies
          4. Batarang options
      4. Summary
    19. Index

Product information

  • Title: MEAN Web Development
  • Author(s): Amos Q. Haviv
  • Release date: September 2014
  • Publisher(s): Packt Publishing
  • ISBN: 9781783983285