Getting Started with Meteor js JavaScript Framework 2nd Edition Learn to develop powerful web applications in minutes with Meteor Isaac Strack - The latest updated ebook version is ready for download
Getting Started with Meteor js JavaScript Framework 2nd Edition Learn to develop powerful web applications in minutes with Meteor Isaac Strack - The latest updated ebook version is ready for download
https://ebookultra.com/download/getting-started-with-grunt-the-
javascript-task-runner-1st-edition-jaime-pillora/
https://ebookultra.com/download/getting-started-with-kubernetes-2nd-
edition-jonathan-baier/
https://ebookultra.com/download/getting-started-with-openshift-1st-
edition-steven-pousty/
https://ebookultra.com/download/getting-started-with-arduino-1st-
edition-massimo-banzi/
Getting Started with SAPUI5 1st Edition Miroslav Antolovic
https://ebookultra.com/download/getting-started-with-sapui5-1st-
edition-miroslav-antolovic/
https://ebookultra.com/download/getting-started-with-electronic-
projects-1st-edition-pretty/
https://ebookultra.com/download/getting-started-with-processing-1st-
edition-casey-reas/
https://ebookultra.com/download/getting-started-with-dwarf-fortress-
learn-to-play-the-most-complex-video-game-ever-made-1st-edition-peter-
tyson/
Isaac Strack
BIRMINGHAM - MUMBAI
www.it-ebooks.info
Getting Started with Meteor.js JavaScript Framework
Second Edition
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78528-554-7
www.packtpub.com
www.it-ebooks.info
Credits
Commissioning Editor
Veena Pagare Indexer
Tejal Daruwale Soni
Acquisition Editors
Subho Gupta Graphics
Jason Monteiro
James Jones
Production Coordinator
Content Development Editor
Manu Joseph
Anish Sukumaran
Cover Work
Technical Editor
Manu Joseph
Menza Mathew
www.it-ebooks.info
About the Author
www.it-ebooks.info
About the Reviewers
Arthur Pham has been working for Thomson Reuters as a lead quantitative
engineer since 2006. He has spent many years designing and implementing
derivative pricing models and still loves to learn new programming languages
such as F#, C++, Python, Flex/ActionScript, C#, Ruby, and JavaScript.
He currently lives in New York, USA, and can be contacted on twitter at @arthurpham.
www.it-ebooks.info
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at service@packtpub.com for more details.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
www.it-ebooks.info
Table of Contents
Preface v
Chapter 1: Setup and Installation 1
Installing using curl 2
Loading an example application 3
Selecting your file's location 4
Loading the example application 4
Starting the example application 4
Previewing the application 5
Help! I made too many changes! 6
Making code changes 6
Changing from Leaderboard to Yay Science! 7
Summary 10
Chapter 2: Reactive Programming…It's Alive! 11
Creating the Lending Library 11
Creating the base application 12
Creating a Collection 14
Having fun with the browser console 15
Adding some data 17
Displaying collections in HTML 18
Cleaning up 22
Creating a reaction 25
Multiple clients 27
Summary 28
[i]
www.it-ebooks.info
Table of Contents
[ ii ]
www.it-ebooks.info
Table of Contents
[ iii ]
www.it-ebooks.info
www.it-ebooks.info
Preface
We live in amazing times. Advances in medicine, communication, physics, and
all other scientific fields provide us with opportunities to create things that were
literally impossible to create only a short while ago.
Yet, we aren't easily amazed. Moore's law has not only affected how fast our
computers are, it has significantly increased our expectations as well. We've
come to expect wondrous advances, and therefore, what was once amazing has
become…well…expected. It's a rare thing, indeed, to find something that takes
us by surprise—something that renews that childhood sense of wonder we all
secretly want back because it was stolen from us.
Well, get ready to regain some of that wonder. A dedicated group of computer
scientists, who were determined to make something wondrous, have created a
new JavaScript framework called Meteor. You may be thinking, "A new JavaScript
framework? That's nothing special." And, if that's all Meteor is, you'd be correct.
However, fortunately for you, that's not the end of the story.
[v]
www.it-ebooks.info
Preface
And the best part is, it's simple to learn, amazingly simple! You will see an
application come to life right before your eyes, and when you look back at the
number of lines of code it took to create and compare it to the traditional methods
of development, you may actually find yourself saying "wow" or "how did they
do that?"
This book will walk you through the major features of Meteor and show you
how to create an application from scratch. By the end of the book, you will have
created a working, useful application, and you will have a solid understanding of
what makes Meteor different. This may sound like hyperbole, but if you're open
to the idea that something innovative and unexpected can qualify as amazing,
then prepare to be amazed!
Chapter 3, Why Meteor Rocks!, helps you to gain an understanding of the design
patterns that Meteor uses and see examples of these powerful patterns in action.
Chapter 4, Templates, teaches you about Meteor Templates in depth and uses
templates to lay the groundwork for your Lending Library application.
Chapter 5, Data – Meteor Style!, helps you to discover how Meteor handles data,
making an enterprise-level application incredibly simple and robust. Implement
Meteor's data handling quickly and effectively in your application.
Chapter 6, Application Structure – Client, Server, and Public (oh my!), shows you what
changes you can make to the default configuration to make your application more
secure, extensible, and user-friendly.
[ vi ]
www.it-ebooks.info
Preface
• Operating systems:
°° Mac OS X 10.7 (Lion) and above versions
°° Linux x86 or x86_64 architectures
°° Windows 7 and above versions
• Meteor:
°° Meteor version 1.1 or above
The following table will guide you to sites that contain more information:
If you are looking for a step-by-step approach to understand how and when to
use one of the most popular and innovative application development frameworks,
this book is for you.
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 an
explanation of their meaning.
Code words in text are shown as follows: "The WebElement class also supports
find methods to find child elements."
[ vii ]
www.it-ebooks.info
Preface
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
//Locate all the Checkbox which are checked by calling jQuery
find() method.
//find() method returns elements in array
List<WebElement> elements = (List<WebElement>)
js.executeScript("return jQuery.find(':checked')");
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:
"Right-click to open the pop-up menu and select the Inspect element option."
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.
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.
[ viii ]
www.it-ebooks.info
Preface
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.
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 would 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/support, 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.
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.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at questions@packtpub.com if you are having a problem with
any aspect of the book, and we will do our best to address it.
[ ix ]
www.it-ebooks.info
www.it-ebooks.info
Setup and Installation
Under the hood, Meteor is really just a bunch of files and scripts, which are designed
to make the building of a web application easier. That's a terrible way to describe
something so elegant, but it helps us to better understand what we're using.
After all, Mila Kunis is really just a bunch of tissue wrapped around bone, with
some vital organs inside. I know you hate me now for that description, but you
get the point. She's beautiful. So is Meteor. But it doesn't do us any good to just
leave it at that. If we want to reproduce that type of beauty on our own, we have
to understand what's really going on.
So, files and scripts… We're going to walk you through how to get the Meteor package
properly installed on your Linux or Mac OS X system, and then see the package of files
and scripts in action.
[1]
www.it-ebooks.info
Setup and Installation
curl (or cURL if you want to get fancy) is a command-line tool used to transfer
files and run scripts using standard URL locations. You probably already knew that,
or you probably don't care. Either way, we've described it and we're now moving on
to using it.
Open a terminal window or the command line, and enter the following command:
curl https://install.meteor.com/ | sh
This will install Meteor on your system. curl is the command to go and fetch the
script. https://install.meteor.com is the URL/location of the script, and sh is,
of course, the location of the script interpreter "Shell", which will run the script.
Once you've run this script, assuming you have an Internet connection and the
proper permissions, you will see the Meteor package downloaded and installed:
[2]
www.it-ebooks.info
Chapter 1
The key thing that we're looking for in the preceding installation text is the launcher
script location:
Writing a launcher script to /usr/local/bin/meteor
This location could vary depending on whether you're running this script in Linux
or Mac OS X, but it puts Meteor into a location where you can then access the Meteor
script from anywhere else. This will become important in a minute. For now, let's see
what kind of friendly message we get when the Meteor installation is finished:
To get started fast:
docs.meteor.com
Great! You've successfully installed Meteor, and you're on your way to create your
first Meteor web application!
We want to use the simplest possible example, just to get an idea of how Meteor
works, so we will be creating the leaderboard example. We'll be using the command
line again. This is awesome news if you still have it open! If not, open a terminal
window and follow these steps.
[3]
www.it-ebooks.info
Other documents randomly have
different content
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com