Book Image

Instant Meteor JavaScript Framework Starter

By : Gabriel Manricks
Book Image

Instant Meteor JavaScript Framework Starter

By: Gabriel Manricks

Overview of this book

<p>Meteor takes many of the cutting edge breakthroughs in web applications that until now have been reserved for larger companies, and makes them available to everyone. Meteor completely rethinks the standard model of web apps, in order to create fast, fluid, and engaging content.<br /><br />Instant Meteor JavaScript Framework Starter takes a behind the scenes look at Meteor, showing you not only the code, but the processes as well. Being completely different from your typical web framework, Meteor requires a dramatically new train of thought when constructing your apps, which we will explore throughout the course of this book. <br /><br />This book starts from the beginning; you don’t need to know about Meteor, NoSQL databases, or even programming best practices, but by the end of the book you should be well versed in each of these.</p> <p>In this book you will learn about the issues that led to the creation of Meteor, and how it fixes these issues. You will learn about writing code for an MVVM architecture and about structuring your code for security and efficiency. We will cover topics such as securing your data and access control, as well as deploying the finished product to the Web.</p> <p>If you have been thinking about getting into this exciting new framework, then Instant Meteor JavaScript Framework Starter is your one-way pass to a painless and fun trip to becoming a pro.</p>
Table of Contents (7 chapters)

Installation


The process of installing Meteor takes place in the terminal. This can sound pretty daunting to people who don’t use it on a daily basis, but I assure you the terminal is nothing more than a chat window on your computer. If you’ve ever sent a text message to someone, then you have all the skills required. The only difference is that you’re chatting with someone who doesn’t speak English, so you have to write the words correctly in order for it to translate your message, which means no shorthand.

Note

Meteor is still in beta and as such, they haven’t got around to creating an official Windows installer. On the same note though, there is an unofficial installer which they recommend for now that you can get by going to: http://win.meteor.com/.

The method I’m going to go talk about now for installing Meteor will work on supported versions of Mac or Linux. As mentioned in the box, you can also try the unofficial installer on Windows but I won’t be covering it here.

The team over at Meteor has created a script to make the installation process as simple as possible. Instead of checking the version of your operating system and architecture, you just get a single script which will do this for you and automatically download the necessary files for your system. So without further ado, just open up a terminal window and type the following:

curl https://install.meteor.com | /bin/sh

Hit Enter and you’re done, but what does this line mean? Well, this single line of text is actually two completely separate commands. The first command listed is curl, which is a tool that can do many things related to web requests, but in our example we are using its most simple function of loading a page. The syntax is: curl web_address, and what you get back is the specified web page in plaintext. We are using it here to grab the script I mentioned earlier, which will check your computer’s info, and get the necessary version of Meteor.

So what does the rest of the command do? Well, like I just said, curl only returns the code in plaintext, it doesn’t run the script. The second half of the line runs the script. In between the two commands, you may have noticed a dividing line (|); this is usually referred to as a pipe and what it does is to take the results from the function to its left and pass that into the command on its right. So we are basically taking the downloaded script and passing it to /bin/sh, which is just the interpreter that handles running bash scripts.

If everything goes well, you should be presented with the following message:

Meteor installed! To get started fast:
  $ meteor create ~/my_cool_app
  $ cd ~/my_cool_app
  $ meteor
Or see the docs at:
 docs.meteor.com

Now we have installed Meteor, but what about all that talk in the previous section about Meteor being a bunch of scripts, or that thing I said about Meteor running on Node.js, that we didn’t have to install node at all?

Well it turns out—surprise!—Meteor takes care of all of this. That single line you wrote, actually downloaded and installed a multitude of files and programs and placed everything in a neat folder on your hard drive.

Now the actual folder can vary from computer to computer, but from my experience the folder on a Mac can be found at /usr/local/meteor/, whereas on Linux it is located at /usr/lib/meteor/. If you’re having trouble finding it, you can run the following command:

sudo find / -name meteor

This will show you a list of files and folders that contain the name meteor. The correct one will show up multiple times, as it contains many occurrences of the word meteor in sub-directories. For example, in my computer the folder is located at /usr/lib/meteor/ and I got four references to that folder in the search (they’re marked with an arrow):

  • /usr/bin/meteor

  • /usr/share/doc/meteor

  • /usr/lib/meteor <-

  • /usr/lib/meteor/bin/meteor <-

  • /usr/lib/meteor/packages/meteor <-

  • /usr/lib/meteor/app/meteor <-

Once you know where your folder is, open it so we can take a look inside. If you want to continue working in the terminal, that’s great, just use cd to change directory and ls to list the files at your current location. So, for example, if your folder is located at /usr/lib/meteor, just type the following to enter the folder:

cd /usr/lib/meteor

Then type the following to see what's inside:

ls

Alternatively, if you want to take a break from the terminal, you can try running the following, and a file window should open at the desired location:

open /usr/lib/meteor

Now I’m not going to go through every file here as there are—according to my computer —2789 files inside. But you should familiarize yourself a little, as it could come in handy down the line.

Meteor’s file structure

This is not crucial information for working with Meteor, but it’s worth mentioning. So I’m going to go through the files pretty quickly, but at the same time I’ll highlight the most interesting items.

  • The app folder: This folder contains the Meteor application itself. It’s written in JavaScript as it runs on Node.js and you really shouldn’t change any files in here. The only thing worth noting is the skel subfolder. This is where Meteor stores the base template. We haven’t created a project yet, but when you do, Meteor copies the contents of this folder and places it as a starting point for your app. So when you get comfortable with Meteor, if you feel you have a better base set up than what is offered, you can come here and modify these files.

  • The bin folder: This folder contains all the executables, for both Meteor and Node.js. The file named meteor is the one that runs when you type meteor in the command line. The other three files are Node.js-specific executables, included as a dependency to Meteor.

  • The examples folder: This folder contains demo projects, provided by the Meteor staff. You can pass one of these as an option when creating a new Meteor project, and instead of loading the contents of the skel folder—like we saw earlier—it will take the contents of the specified demo’s folder, as a starter for your application.

  • The include folder: Nothing interesting to say about this one. If you are familiar with languages such as C and C++, then you’ll know each source file has its own header file for defining the script’s properties. The include folder contains all the header files required by Node.js. This is another folder you probably won’t be touching.

    • include

  • The lib folder: Being a Node.js app, Meteor takes advantage of many other packages to accomplish its tasks. In Node.js, you have the ability to download third-party modules built by anyone, to incorporate into your application. This doesn’t really have much to do with building Meteor applications, but if you are familiar with Node.js, then it’s a good case study to see what kinds of packages went into this. But again this is just a dependency folder for Meteor; so strictly speaking, there’s nothing to play around with here.

  • The mongodb folder: You may have heard of mongoDB, but if not it’s a noSQL database that stores its data in documents. It is the default database in Meteor, so we will be going into more detail in the later sections. This folder just contains a copy of mongoDB for use in your Meteor applications.

    • mongodb

  • The packages folder: I did want to display the contents of this directory, but it has too many files; still it’s worth taking a look. Meteor is a modular framework, which allows you to attach or detach different packages to your application. Some of these may seem familiar to you such as jQuery or Coffescript. You don’t have to worry about these too much; they are basically here for your own benefit. You can choose to use or not use as many or as little as you want. In the course of this book we will be taking advantage of a few of these.

    • packages

  • The share folder: This folder contains the help file for Node. This file is also known as the man page, because the command you use to access it is labeled man (after manual). To view it, just type man share/man/man1/node.1 from within the meteor folder while in the terminal. Although it’s not too relevant as it’s the manual for Node.js, which we won’t really be using.

    • share

In this section you’ve learned how to install Meteor and hopefully you became a little more comfortable with the terminal window. We also went through all the directories in the underlying meteor folder, and you got a rundown of how Meteor is structured.

We are now ready to begin creating our very own Meteor applications, and in the next section we will take a look at the structure of a Meteor program itself!

Tip

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.