Meteor Cheat Sheet

Notes covering the critical Meteor concepts that will help you get up and running.

Meteor

Meteor is a full-stack Javascript framework for building web and native applications.

Directory Structure

  • Files in the Client folder are only rendered on the Client.
  • Files in the Server folder are only rendered on the Server.
  • Files in Lib are rendered on both Client and Server.
  • Files in Public are rendered to the Client.

Routing

Routing requires middleware/package. Most common:
  • Flow-router
  • Iron-router

Global helpers (functions)

  • Create helper in lib directory (“/lib/helpers.js”)
  • Syntax: Template.registerHelper(‘helperName’, ‘function () {});

Collections

  • Create a collection in lib (Collection = new Mongo.Collection(‘collection’);

CRUD

  • Insert: collection.insert(doc, [callback]);
  • Update: collection.update(selector, modifier, [options], [callback])
  • Remove: collection.remove(selector, [callback])

Sessions

  • Sessions are global objects on the client. Can be used to store key-value pairs
  • Session.set(key, value) – New session
  • Session.set(key) – Get the value of session

Templates

Creating a new template (template name=“foo”> in HTML creates a template object named Template.foo.
Events
Template.myTemplate.events – Specify events for this template like click, dblclick
Helpers
Template.myTemplate.helpers – Specify template helpers (methods) available to this template
onRendered
Template.mytemplate.onRendered – Methods to be called when template is inserted into DOM

Packages

Middleware/extensions to be used with app.
NPM packages with Meteor

Accounts

  • Basic package is ‘accounts-base’
  • accounts-password, accounts-facebook, accounts-github, accounts-google, accounts-meetup, accounts-twitter
  • Meteor.user() – Get current user record or null if no user is logged in
Accounts UI
  • Add accounts-ui package
  • Add at least one login provider package:
    • accounts-password
    • accounts-facebook
    • accounts-github
    • etc
  • Add {{> loginButtons}} helper to an HTML file
  • This will place login widget on page

Author: Husam

Husam Machlovi has pitched to, and developed relationships with, top Fortune 100 companies. He's designed digital experiences that have generated millions in revenue. At his company, With Pulp, he leads Product Strategy & Design where he crafts product stories and interfaces that people love.

Leave a Reply

Your email address will not be published. Required fields are marked *