You are previewing Building Single-page Web Apps with Meteor.
O'Reilly logo
Building Single-page Web Apps with Meteor

Book Description

Build real-time apps at lightning speed using the most powerful full-stack JavaScript framework

In Detail

Meteor is the best JavaScript platform on the Web that allows you to build real-time web applications quickly and easily and in pure JavaScript. It comes with a full build process that takes care of everything, from development to production, with no need for configuration. This book takes you from the installation of Meteor to building a fully working web blog (including backend) to create and edit posts.

You will start with the basic concepts and folder structure of a Meteor project, learning how Meteor templates work. Learn how to retrieve and send data to the server and manipulate the database content. Routing will later make your example app look and behave like a real website. Next, you'll get to grips with Meteor's reactivity concept that can rerun functions when data changes while you're building your own reactive object, and package it later for drop-in use. After your app is ready, the book continues with ways of deploying your app on different types of servers. Finally, we will take a look at testing packages and the application itself.

What You Will Learn

  • Create reactive templates that update themselves when data changes

  • Use database queries on the client and the server to retrieve, sort, and manipulate datasets

  • Understand data synchronization using a publication/subscription model and make API calls a thing of the past

  • Discover how you can secure your data flow on the server side to keep confidential data secret

  • Add routing to a single-page application and make it appear like a real website

  • Build your own advanced reactive objects and make everything rerun when you want

  • Make your own Meteor packages and learn how to make them public

  • Unit test your packages and Meteor applications

  • 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 files e-mailed directly to you.

    Table of Contents

    1. Building Single-page Web Apps with Meteor
      1. Table of Contents
      2. Building Single-page Web Apps with Meteor
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. 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
      9. 1. Getting Started with Meteor
        1. The full-stack framework of Meteor
        2. Meteor's requirements
          1. Using Chrome's developer tools
          2. Using Git and GitHub
        3. Installing Meteor
          1. Installing Git
        4. Creating our first app
          1. Creating a good folder structure
          2. Preadd style files
        5. Adding basic packages
          1. Adding a core package
          2. Adding a third-party package
        6. Variable scopes
        7. Meteor's folder conventions and loading order
          1. Loading assets on the server
        8. Meteor's command-line tool
          1. Updating Meteor
          2. Deploying Meteor
        9. Summary
      10. 2. Building HTML Templates
        1. Writing templates in Meteor
        2. Building the basic templates
        3. Adding templates and partials
        4. Displaying data with template helpers
        5. Setting the data context for a template
          1. Using the {{#with}} block helper
        6. "this" in template helpers and template callbacks
        7. Adding events
        8. Block helpers
        9. Listing posts
        10. Spacebars syntax
          1. Accessing parent data contexts
          2. Passing data to helpers
        11. Summary
      11. 3. Storing Data and Handling Collections
        1. Meteor and databases
        2. Setting up a collection
        3. Adding post examples
        4. Querying a collection
        5. Updating a collection
        6. Database everywhere
        7. Differences between client and server collections
        8. Summary
      12. 4. Controlling the Data Flow
        1. Syncing data – the current Web versus the new Web
        2. Removing the autopublish package
        3. Publishing data
        4. Publishing only parts of data
        5. Publishing specific fields
        6. Lazy loading posts
        7. Switching subscriptions
        8. Some notes on data publishing
        9. Summary
      13. 5. Making Our App Versatile with Routing
        1. Adding the iron:router package
        2. Setting up the router
        3. Switching to a layout template
        4. Adding another route
        5. Moving the posts subscription to the Home route
        6. Setting up the post route
          1. Creating a single-post publication
          2. Adding the post route
          3. Linking the posts
        7. Changing the website's title
        8. Summary
      14. 6. Keeping States with Sessions
        1. Meteor's session object
          1. A better way for simple reactivity
        2. Using sessions in template helpers
          1. Session and hot code pushes
        3. Rerunning functions reactively
          1. Stopping reactive functions
        4. Using autorun in a template
        5. The reactive session object
        6. Summary
      15. 7. Users and Permissions
        1. Meteor's accounts packages
        2. Adding the accounts packages
        3. Adding admin functionality to our templates
          1. Adding a link for new posts
          2. Adding the link to edit posts
          3. Adding the login form
        4. Creating the template to edit posts
        5. Creating the admin user
          1. Adding permissions
          2. A note on security
        6. Creating routes for the admin
          1. Preventing visitors from seeing the admin routes
        7. Summary
      16. 8. Security with the Allow and Deny Rules
        1. Adding a function to generate slugs
        2. Creating a new post
          1. Saving a post
        3. Editing posts
          1. Updating the current post
        4. Restricting database updates
          1. Removing the insecure package
          2. Adding our first allow rules
        5. Adding a deny rule
        6. Adding posts using a method call
          1. Method stubs and latency compensation
          2. Changing the button
          3. Adding the method
        7. Calling the method
        8. Summary
      17. 9. Advanced Reactivity
        1. Reactive programming
          1. The invalidating cycle
        2. Building a simple reactive object
          1. Rerunning functions
        3. Creating an advanced timer object
        4. Reactive computations
          1. Stopping reactive functions
          2. Preventing run at start
          3. Advanced reactive objects
        5. Summary
      18. 10. Deploying Our App
        1. Deploying on
          1. Deploying on using a domain name
          2. Backup and restore databases hosted on
        2. Deploying on other servers
          1. Bundling our app
          2. Deploying using Demeteorizer
          3. Deploying using Meteor Up
            1. Setting up the server
            2. Deploying with mup
        3. Outlook
        4. Summary
      19. 11. Building Our Own Package
        1. The structure of a package
        2. Creating our own package
          1. Adding the package metadata
          2. Adding the package
        3. Releasing our package to the public
          1. Publishing our package online
          2. Updating our package
        4. Summary
      20. 12. Testing in Meteor
        1. Types of tests
        2. Testing packages
          1. Adding package tests
          2. Running the package tests
        3. Testing our meteor app
          1. Testing using Jasmine
            1. Adding unit tests to the server
            2. Adding integration tests to the client
              1. Adding a test for the visitors
              2. Adding a test for the admin
        4. Acceptance tests
          1. Nightwatch
          2. Laika
        5. Summary
      21. A. Appendix
        1. List of Meteor's command-line tool commands
        2. The iron:router hooks
      22. Index