Catalog / Meteor.js Cheat Sheet
Meteor.js Cheat Sheet
A comprehensive cheat sheet for Meteor.js, covering core concepts, commands, and best practices for efficient development.
Core Concepts
Key Principles
Data on the Wire: Only data is sent, not HTML. This minimizes bandwidth and maximizes responsiveness. |
Latency Compensation: Simulate server results on the client for a smoother user experience. |
Full Stack Reactivity: Changes in the database are automatically reflected in the UI. |
One Language: Use JavaScript (or TypeScript) for both the client and the server. |
Directory Structure
|
|
|
|
Data Flow
Client interacts with UI -> Client-side methods -> Server-side methods (if needed) -> MongoDB -> Server publishes data -> Client subscribes to data -> UI updates reactively. |
Commands & Syntax
Project Setup
|
Create a new Meteor project. |
|
Run the Meteor application. |
|
Add a Meteor package to the project. |
|
Remove a Meteor package from the project. |
Collections
|
Create a new MongoDB collection. |
|
Insert a document into the collection. |
|
Update a document in the collection. |
|
Remove a document from the collection. |
|
Find documents and return them as an array. |
Methods
|
Define a Meteor method. |
|
Call a Meteor method from the client. |
Publish and Subscribe
Publishing Data
Publishes a set of documents from a collection. |
Example: Publish all todos for the current user.
|
Subscribing to Data
Subscribes to a publication from the client. |
Example: Subscribe to the ‘todos’ publication.
|
Controlling Data Access
Use
Note: In production, use more restrictive rules to prevent unauthorized access. |
Templates and UI
Blaze Templates
Define templates using HTML with Handlebars-like syntax.
|
Use template helpers to provide data to templates.
|
Handle events in templates.
|
Using React or Vue
Meteor can be integrated with React or Vue for more complex UIs. |
Example: Using React with Meteor:
Then, create React components and use |
Session Variables
Note: Session variables are deprecated. Use ReactiveVar or ReactiveDict instead.
|