documentation - meteor

Download Documentation - Meteor

Post on 20-Feb-2016

19 views

Category:

Documents

1 download

Embed Size (px)

DESCRIPTION

Documentation - Meteor JS

TRANSCRIPT

  • 11/10/15 Documentation - Meteor

    docs.meteor.com/#/basic/underscore 1/27

    Meteor is an ultra-simple environment for building modern websites. What once took weeks, even withthe best tools, now takes hours with Meteor.

    The web was originally designed to work in the same way that mainframes worked in the 70s. The applicationserver rendered a screen and sent it over the network to a dumb terminal. Whenever the user did anything, thatserver rerendered a whole new screen. This model served the Web well for over a decade. It gave rise toLAMP, Rails, Django, PHP.

    But the best teams, with the biggest budgets and the longest schedules, now build applications in JavaScriptthat run on the client. These apps have stellar interfaces. They don't reload pages. They are reactive: changesfrom any client immediately appear on everyone's screen.

    They've built them the hard way. Meteor makes it an order of magnitude simpler, and a lot more fun. You canbuild a complete application in a weekend, or a sufficiently caffeinated hackathon. No longer do you need toprovision server resources, or deploy API endpoints in the cloud, or manage a database, or wrangle an ORMlayer, or swap back and forth between JavaScript and Ruby, or broadcast data invalidations to clients.

    Quick start!

    Meteor supports OS X, Windows, and Linux.

    On Windows? Download the official Meteor installer here.

    On OS X or Linux? Install the latest official Meteor release from your terminal:

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

    The Windows installer supports Windows 7, Windows 8.1, Windows Server 2008, and Windows Server 2012.The command line installer supports Mac OS X 10.7 (Lion) and above, and Linux on x86 and x86_64architectures.

    Once you've installed Meteor, create a project:

    meteor create myapp

    Run it locally:

    cd myapp

    meteor

    # Meteor server running on: http://localhost:3000/

    Then, open a new terminal tab and unleash it on the world (on a free server we provide):

    meteor deploy myapp.meteor.com

    Principles of Meteor

    Data on the Wire. Meteor doesn't send HTML over the network. The server sends data and lets theclient render it.

    One Language. Meteor lets you write both the client and the server parts of your application inJavaScript.

    Database Everywhere. You can use the same methods to access your database from the client or the

  • 11/10/15 Documentation - Meteor

    docs.meteor.com/#/basic/underscore 2/27

    server.

    Latency Compensation. On the client, Meteor prefetches data and simulates models to make it looklike server method calls return instantly.

    Full Stack Reactivity. In Meteor, realtime is the default. All layers, from database to template, updatethemselves automatically when necessary.

    Embrace the Ecosystem. Meteor is open source and integrates with existing open source tools andframeworks.

    Simplicity Equals Productivity. The best way to make something seem simple is to have it actually besimple. Meteor's main functionality has clean, classically beautiful APIs.

    Learning Resources

    There are many community resources for getting help with your app. If Meteor catches your interest, we hopeyou'll get involved with the project!

    TUTORIALGet started fast with the official Meteor tutorial!

    STACK OVERFLOWThe best place to ask (and answer!) technical questions is on Stack Overflow. Be sure to add themeteor tag to your question.

    FORUMSVisit the Meteor discussion forums to announce projects, get help, talk about the community, ordiscuss changes to core.

    GITHUBThe core code is on GitHub. If you're able to write code or file issues, we'd love to have your help. Pleaseread Contributing to Meteor for how to get started.

    Command Line Tool

    meteor help

    Get help on meteor command line usage. Running meteor help by itself will list the common meteorcommands. Running meteor help will print detailed help about meteor .

    meteor create

    Make a subdirectory called and create a new Meteor app there.

    meteor run

    Serve the current app at http://localhost:3000 using Meteor's local development server.

    meteor debug

    Run the project with Node Inspector attached, so that you can step through your server code line by line. Seemeteor debug in the full docs for more information.

    meteor deploy

    Bundle your app and deploy it to . Meteor provides free hosting if you deploy to.meteor.com as long as is a name that has not been claimed by someone else.

    meteor update

    Update your Meteor installation to the latest released version and then (if meteor update was run from an appdirectory) update the packages used by the current app to the latest versions that are compatible with all other

  • 11/10/15 Documentation - Meteor

    docs.meteor.com/#/basic/underscore 3/27

    packages used by the app.

    meteor add

    Add a package (or multiple packages) to your Meteor project. To query for available packages, use themeteor search command.

    meteor remove

    Remove a package previously added to your Meteor project. For a list of the packages that your application iscurrently using, use the meteor list command.

    meteor mongo

    Opens a MongoDB shell for viewing and/or manipulating collections stored in the database. Note that youmust already be running a server for the current app (in another terminal window) in order for meteor mongo toconnect to the app's database.

    meteor reset

    Reset the current project to a fresh state. Removes all local data.

    If you use meteor reset often, but you have some initial data that you don't want to discard, consider usingMeteor.startup to recreate that data the first time the server starts up:

    if (Meteor.isServer) {

    Meteor.startup(function () {

    if (Rooms.find().count() === 0) {

    Rooms.insert({name: "Initial room"});

    }

    });

    }

    File Structure

    Meteor is very flexible about how you structure the files in your app. It automatically loads all of your files, sothere is no need to use or tags to include JavaScript or CSS.

    Default file loading

    If files are outside of the special directories listed below, Meteor does the following:

    1. HTML templates are compiled and sent to the client. See the templates section for more details.2. CSS files are sent to the client. In production mode they are automatically concatenated and minified.3. JavaScript is loaded on the client and the server. You can use Meteor.isClient and Meteor.isServer

    to control where certain blocks of code run.

    If you want more control over which JavaScript code is loaded on the client and the server, you can use thespecial directories listed below.

    Special directories

    /client

    Any files here are only served to the client. This is a good place to keep your HTML, CSS, and UI-relatedJavaScript code.

    /server

    Any files in this directory are only used on the server, and are never sent to the client. Use /server to storesource files with sensitive logic or data that should not be visible to the client.

    /public

  • 11/10/15 Documentation - Meteor

    docs.meteor.com/#/basic/underscore 4/27

    Files in /public are served to the client as-is. Use this to store assets such as images. For example, if youhave an image located at /public/background.png, you can include it in your HTML with or in your CSS with background-image:url(/background.png). Note that /public is not part of the image URL.

    /private

    These files can only be accessed by server code through Assets API and are not accessible to the client.

    Read more about file load order and special directories in the Structuring Your App section of the full APIdocumentation.

    Building Mobile Apps

    Once you've built your web app with Meteor, you can easily build a native wrapper for your app and publish it tothe Google Play Store or iOS App Store with just a few commands. We've put a lot of work into making thesame packages and APIs work on desktop and mobile, so that you don't have to worry about a lot of the edgecases associated with mobile app development.

    Installing mobile SDKs

    Install the development tools for Android or iOS with one command:

    meteor install-sdk android # for Android

    meteor install-sdk ios # for iOS

    Adding platforms

    Add the relevant platform to your app:

    meteor add-platform android # for Android

    meteor add-platform ios # for iOS

    Running on a simulator

    meteor run android # for Android

    meteor run ios # for iOS

    Running on a device

    meteor run android-device # for Android

    meteor run ios-device # for iOS

    Configuring app icons and metadata

    You can configure your app's icons, title, version number, splash screen, and other metadata with the specialmobile-config.js file.

    Learn more about Meteor's mobile support on the GitHub wiki page.

    The Meteor API

  • 11/10/15 Documentation - Meteor

    docs.meteor.com/#/basic/underscore 5/27

    Client

    Your JavaScript code can run in two environments: the client (browser), and the server (a Node.js container ona server). For each function in this API reference, we'll indicate if the function is available just on the client, juston the server, or Anywhere.

    Templates

    In Meteor, views are defined in templates. A template is a snippet of HTML that can include dynamic data. Youcan also interact with your templates from JavaScript code to insert data and listen to events.

    Defining Templates in HTML

    Templates are defined in .html files that can be located anywhere in your Meteor project folder except thes