10x Developer
  • Introduction
  • HTML
    • HTML DOM Jquery
    • HTML: Form
    • CSS
    • CSS Layout
    • CSS Flexbox
    • CSS Grid
    • SASS/LESS
    • CSS/LESS/SASS Cookbook
    • Bootstrap
  • JavaScript
    • JavaScript
    • ES6
    • TypeScript
    • JavaScript Testing
    • JavaScript Event Loop
    • DOM
    • Web APIs
    • JSON
    • RegEx
    • Functional Programming
    • JavaScript Lib
    • CoffeeScript
    • CoffeeScript to ES6 cheatsheet
  • Angular.js
    • Angular
    • Angular Cookbook
    • Angular Mistakes I Made
    • Angular 1.x
  • React.js
    • React.js
  • Node
    • Node.js
    • CLI command line tool
    • Electron / Atom
    • NW.js (node-webkit)
  • Serverless
    • AWS Lambda
    • Google Cloud Function
    • Actions on Google / Google Assistant
  • Full Stack Development
    • HTTP
    • Meteor
    • MongoDB
    • Digital Ocean
    • UI
    • Sketch
    • Web Dev Resources
  • Lang
    • Ruby
  • Know Your Tools
    • Chrome DevTools
    • Editor: VS Code
    • Editor: Vim
    • Editor: Sublime
    • Editor: Atom
    • Windows
    • Git
    • Linux / Bash
    • Mac
  • Cheatsheets
Powered by GitBook
On this page
  • Guide
  • How to do logging via winston and loggly
  • How to send email using SendGrid
  • DDP
  • Performance
  • Client Side
  • Store data in template instance using ReactiveVar
  • Packages
  • fs
  1. Full Stack Development

Meteor

PreviousHTTPNextMongoDB

Last updated 6 years ago

see also

Guide

Kadira Academy

  • _ (don't do data management and auth on route level)

  • x

  • _

Little Projects

Tools:

  • admin for mongo db:

How to do logging via winston and loggly

Inspired from this guide: 1. Sign up 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

  • meter add email

DDP

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

  • Users.find({}, {fields: {password: 0, hash: 0}})

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

  • 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

  • collection-fs

    • go directly to S3

    • Set ACL to 'private' so only your meteor app can download the file

    • Use S3 sdk to generate pre-signed url for public download

Or see my

regiter

with (Mail capability):

Then you can use the mail package to send email:

Reference:

_

_

_

limit (cannot do both inclusion/exclusion) on publication:

, problem demo on

Use to avoid re-sub when route changes

Try

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

tips:

slingshot:

Upload and download in server

Upload to any path in server:

https://gist.github.com/hamxiaoz
routing guide: flow router
Meteor Performance 101
bulletproof
https://themeteorchef.com/snippets/importing-csvs/
http://www.drmongo.com/
https://meteorhacks.com/logging-support-for-meteor
loggly
Medium post
sendgrid
create different user
https://app.sendgrid.com/settings/credentials
https://gist.github.com/aaronthorp/8410571
https://themeteorchef.com/snippets/using-the-email-package/
Why not Mandrill?
Why SendGrid?
DDP Spec
meteor-ddp-analyzer
add index
Mongodb aggregation
https://kadira.io/academy/meteor-performance-101/content/reducing-pubsub-data-usage#counting-on-the-server-side
fields
Infinite Scrolling using limit
Pagination
MeteorPad
subscription manager
https://kadira.io/academy/meteor-performance-101/content/improve-cpu-and-network-usage
https://kadira.io/academy/meteor-performance-101/content/know-your-observers
CPU profiling
analysis
ReactiveVar
template instance
http://blog.zipboard.co/2015/11/23/cfs-tips-and-tricks-for-meteorjs/
https://atmospherejs.com/edgee/slingshot
https://github.com/peerlibrary/meteor-aws-sdk
http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-services.html
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
https://github.com/VeliovGroup/Meteor-Files/
https://github.com/tomitrescak/meteor-uploads