Meteor

see also https://gist.github.com/hamxiaoz

Guide

Kadira Academy

Little Projects

Tools:

How to do logging via winston and loggly

Inspired from this guide: https://meteorhacks.com/logging-support-for-meteor 1. Sign up loggly 2. add 'winston' and 'winston-loggly' to package.json 3. code Don't forget Meteor.npmRequire is only available on server side 4. LOGGER.info will output on console and send events to loggly

# Setup logging in server/config.js
@LOGGER = Meteor.npmRequire 'winston'
Meteor.npmRequire 'winston-loggly'
LOGGER.add(LOGGER.transports.Loggly, {
  token: "YOUR-TOKEN",
  subdomain: "YOUR-DOMAIN",
  tags: ["YOUR-TAG"],
  json:true,
  handleExceptions: true, # handle exception in logger
  humanReadableUnhandledException: true
});
LOGGER.existOnError = false # don't exit on error
LOGGER.info 'logger started'

How to send email using SendGrid

Or see my Medium post

DDP

DDP Spec

meteor-ddp-analyzer

Performance

DB

  • When setup db, enable db oplog

    • If your query has a limit but not a sort specifier, your query can't take advantage of oplog

      Posts.find({category: "meteor"}, {limit: 10});

Counting on the server side

Publication

Subscription

_ Observer

Reduce wait time: this.unblock()

  • this.unblock will allow the next available DDP message to process without waiting for the current method.

  • Use it when your methods and subscriptions (enabled via this package: meteor add meteorhacks:unblock) don't depend on others

  • Do not use it when a method will cause side effects and subsequent methods will depend on those side effects.

    For example you have a method to update name and another method to send notification emails about the updated name, if unblock is used, the email might contain the old name.

  • This is all on a per client basis: there no blocking involved globally.

Try CPU profiling analysis

Client Side

Store data in template instance using ReactiveVar

You can store ReactiveVar in the template instance. A ReactiveVar is similar to a Session variable, with a few differences:

  • ReactiveVars don't have global names, like the "foo" in Session.get("foo"). Instead, they may be created and used locally, for example attached to a template instance, as in: this.foo.get(). // 'this' is the template instance

  • ReactiveVars are not automatically migrated across hot code pushes, whereas Session state is.

  • ReactiveVars can hold any value, while Session variables are limited to JSON or EJSON.

if (Meteor.isClient) {  
  Template.hello.created = function () {
    // counter starts at 0
    this.counter = new ReactiveVar(0);
  };

  Template.hello.helpers({
    counter: function () {
      return Template.instance().counter.get();
    }
  });

  Template.hello.events({
    'click button': function (event, template) {
      // increment the counter when button is clicked
      template.counter.set(template.counter.get() + 1);
    }
  });
}

Packages

fs

Last updated