10x Developer
Search…
Meteor

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
1
# Setup logging in server/config.js
2
@LOGGER = Meteor.npmRequire 'winston'
3
Meteor.npmRequire 'winston-loggly'
4
LOGGER.add(LOGGER.transports.Loggly, {
5
token: "YOUR-TOKEN",
6
subdomain: "YOUR-DOMAIN",
7
tags: ["YOUR-TAG"],
8
json:true,
9
handleExceptions: true, # handle exception in logger
10
humanReadableUnhandledException: true
11
});
12
LOGGER.existOnError = false # don't exit on error
13
LOGGER.info 'logger started'
Copied!

How to send email using SendGrid

Or see my Medium post

DDP

DDP Spec

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.

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.
1
if (Meteor.isClient) {
2
Template.hello.created = function () {
3
// counter starts at 0
4
this.counter = new ReactiveVar(0);
5
};
6
7
Template.hello.helpers({
8
counter: function () {
9
return Template.instance().counter.get();
10
}
11
});
12
13
Template.hello.events({
14
'click button': function (event, template) {
15
// increment the counter when button is clicked
16
template.counter.set(template.counter.get() + 1);
17
}
18
});
19
}
Copied!

Packages

fs