Book Image

Building Single-page Web Apps with Meteor

By : Fabian Vogelsteller
Book Image

Building Single-page Web Apps with Meteor

By: Fabian Vogelsteller

Overview of this book

Table of Contents (21 chapters)
Building Single-page Web Apps with Meteor
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Thank you for buying this book. You made a great choice for a new step in frontend and JavaScript technology. The Meteor framework is not just another library that aims to make things easier. It is a complete solution for a web server, client logic, and templates. Additionally, it contains a complete build process, which will make working for the Web by chunks faster. Thanks to Meteor, linking your scripts and styles is a thing of the past, as the automatic build process takes care of everything for you. Surely, this is a big change, but you will soon love it, as it makes extending your app as fast as creating a new file.

Meteor aims to create single-page applications where real time is the default. It takes care of the data synchronization and updating of the DOM. If data changes, your screen will be updated. These two basic concepts make up a lot of the work we do as web developers, and with Meteor this happens without any extra line of code.

In my opinion, Meteor is a complete game changer in modern web development. It introduces the following patterns as defaults:

  • Fat clients: All of the logic resides on the client. HTML is only sent on the initial page load

  • JavaScript and the same API are used on both the client and the server

  • Real time: Data synchronizes automatically to all clients

  • A "database everywhere" approach, allowing database queries on the client side

  • Publish/subscribe patterns for web server communication as the default

Once you have used all these new concepts, it is hard to go back to the old way of doing things where so much time goes only into preparing the app's structure while linking files or wrapping them into Require.js modules, writing endpoints, and writing code to request and send data back and forth.

While reading this book, you will be introduced step by step to these concepts and how they connect together. We will build a blog, with the backend to edit posts. A blog is a good example, as it uses listings of posts, different routes for each post, and an admin interface to add new posts, providing all we need to fully understand Meteor.

What this book covers

Chapter 1, Getting Started with Meteor, describes the necessary steps to install and run Meteor, while also going into details about the folder structure of a Meteor project and, in particular, the Meteor project we will build.

Chapter 2, Building HTML Templates, shows how reactive templates are built using handlebars such as syntax and how simple it is to display data in them.

Chapter 3, Storing Data and Handling Collections, covers database usage on the server and the client sides.

Chapter 4, Controlling the Data Flow, gives an introduction to Meteor's publication/subscription pattern, which is used to synchronize data between the server and the clients.

Chapter 5, Making Our App Versatile with Routing, teaches us how to set up routes and make our app behave and feel like a real website.

Chapter 6, Keeping States with Sessions, discusses the reactive Session object and how it can be used.

Chapter 7, Users and Permissions, describes the creation of users and how the login process works. At this time, we'll create the backend part for our blog.

Chapter 8, Security with the Allow and Deny Rules, covers how the data flow can be limited to certain users to prevent everybody from making changes to our database.

Chapter 9, Advanced Reactivity, shows how we can build our own custom reactive object that can rerun a function based on a time interval.

Chapter 10, Deploying Our App, covers how to deploy the app using Meteor's own deploy service and also on your own infrastructure.

Chapter 11, Building Our Own Package, describes how to write a package and publicize it on Atmosphere for everybody to use.

Chapter 12, Testing in Meteor, shows how packages can be tested using Meteor's own tinytest package, as well as using third-party tools to test the Meteor application itself.

Appendix, contains a list of Meteor commands as well as iron:router hooks and their descriptions.

What you need for this book

To follow the examples in the chapters, you will need a text editor to write the code. I highly recommend Sublime Text as your IDE, as it has a wide range of plugins for almost every task a web developer could think of.

You will also need a modern browser to see your results. As many examples use the browser console to make changes to the database and to see the results of the code snippets, I recommend Google Chrome. Its Developer tools web inspector has everything a web developer needs to work and debug websites with ease.

Additionally, you can use Git and GitHub to store your success every step along the way and in order to go back to the previous versions of your code.

The code examples for each chapter will also be available on GitHub at https://github.com/frozeman/book-building-single-page-web-apps-with-meteor, where each commit in this repository correlates with one chapter of the book, giving you an easy way to see what was added and removed in each step along the way.

Who this book is for

This book is for web developers who want to get into the new paradigm of single-page, real-time applications. You don't need to be a JavaScript professional to follow along, but certainly a good basic understanding will make this book a valuable companion.

If you have heard about Meteor but haven't yet used it, this book is definitely for you. It will teach you everything you need to understand and use Meteor successfully. If you have used Meteor before but want to get a deeper insight, then the final chapter will help you improve your understanding of custom reactive objects and writing packages. Testing is probably the least covered topic in the Meteor community right now, so by reading the final chapter, you will easily gain an understanding of how to make your apps robust using automated tests.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and explanations of their meanings.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "With Meteor, we never have to link files with the <script> tags in HTML."

A block of code is set as follows:

<head>
  <title>My Meteor Blog</title>
</head>
<body>
  Hello World
</body>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<div class="footer">
  <time datetime="{{formatTime timeCreated "iso"}}">Posted {{formatTime timeCreated "fromNow"}} by {{author}}</time>
</div>

Any command-line input or output is written as follows:

$ cd my/developer/folder
$ meteor create my-meteor-blog

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "However, now when we go to our browser, we will still see Hello World."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

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

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.