Meteor Documentation
website·Indexed 41 days ago
https://guide.meteor.com/Comprehensive guides for the Meteor framework, covering application structure, security, routing, and deployment. Includes detailed migration paths for versions 1.3 through 2.13, as well as instructions for managing accounts, defining Meteor Methods, using npm packages, and writing Atmosphere packages.
What's inside Meteor
- Methods are Meteor's remote procedure call (RPC) system, acting as API endpoints for the server. They are primarily used to save user input and data sent from the client to the database. Unlike standard HTTP POST requests, Methods are tightly integrated with Meteor's pub/sub and data loading systems to enable Optimistic UI, allowing the client to simulate server-side actions for a more responsive user experience.
Overview of Meteor Cordova integration
Meteor integrates with Apache Cordova to allow developers to build iOS and Android apps using the same codebase as a web app. The app runs in an embedded web view, bundling assets locally for faster loading and providing access to native device features via plugins. Key benefits include support for hot code push (updating apps without app store resubmission) and the ability to use standard web elements for the UI.Overview of the Meteor platform
v2.10Meteor is a full-stack JavaScript platform for building modern web and mobile applications. It enables development in a single language (JavaScript) across the server, browser, and mobile devices. Key architectural features include:
- Data on the wire: The server sends data instead of HTML, and the client handles rendering.
- Full stack reactivity: The UI automatically reflects the current state of the data with minimal effort.
- Integrated Build Tool: Includes a build system and a curated set of packages from the Node.js and JavaScript ecosystem.
Overview of the Meteor platform
Meteor is a full-stack JavaScript platform for building connected-client reactive web and mobile applications. Key architectural features include:
- Single Language: Use JavaScript across the application server, web browser, and mobile devices.
- Data on the Wire: The server transmits data instead of HTML; the client is responsible for rendering.
- Full Stack Reactivity: The UI automatically reflects the current state of the data with minimal manual effort.
- Integrated Tooling: Includes a build tool and a curated set of packages from the Node.js and JavaScript ecosystems.
Build and run a custom Meteor deployment
Meteor applications can be deployed as standard Node.js apps using themeteor buildcommand. It is critical to specify the correct target architecture using the--architectureflag to avoid runtime errors. The resulting bundle must be run with a Node.js version that matches the one used by the Meteor version (checkmeteor node -vor the.node_version.txtfile in the bundle).# 1. Install production dependencies and build for target architecture npm install --production meteor build /path/to/build --architecture os.linux.x86_64 # 2. Run the application from the bundle directory cd my_build_bundle_directory (cd programs/server && npm install) MONGO_URL=mongodb://localhost:27017/myapp ROOT_URL=http://my-app.com PORT=3000 node main.jsUnderstand Meteor's built-in user account features
Meteor provides core functionality for tracking user login state via the DDP protocol and the
accounts-basepackage.- DDP
userId: The DDP protocol tracks login state using auserIdfield on the connection. This allows you to accessthis.userIddirectly inside Methods and Publications, and access the user ID on the client. accounts-basepackage: This is the core of Meteor's account system. It provides:- The
Meteor.userscollection with a standard schema. - Client-side singletons
Meteor.userId()andMeteor.user()to represent the current login state. - Generic methods for logging out, validating users, and tracking state.
- An API for registering new login handlers used by other account packages.
- The
- DDP
Structure client and server entry points
To maintain a clean architecture, it is recommended to use exactly two eagerly loaded entry points:
client/main.jsandserver/main.js.Meteor enforces strict environment isolation:
- Files in any directory named
server/are only available on the server. - Files in any directory named
client/are only available on the client. - You cannot
importa file from aclient/directory into aserver/directory (or vice versa), even if the file is inside animports/subdirectory.
- Files in any directory named
Understand Meteor publications and subscriptions
Meteor uses the Distributed Data Protocol (DDP) to enable two-way data transfer. Instead of traditional REST endpoints, Meteor uses publications and subscriptions to sync data.
- Publication: A named API on the server that defines a set of data to be sent to the client.
- Subscription: A client-side request to connect to a publication. Once initialized, the client receives an initial batch of data and subsequent incremental updates as the data changes on the server.
This mechanism effectively bridges a server-side MongoDB collection with the client-side Minimongo cache.
Enable Two-Factor Authentication with accounts-2fa
Theaccounts-2fapackage introduced in Meteor 2.7 provides two-factor authentication for applications usingaccounts-passwordoraccounts-passwordless. Adding the package does not require mandatory changes to your application, but you can use the functions provided by the package to implement 2FA for your users.Understand the Hot Code Push (HCP) workflow
Hot Code Push in Meteor works by calculating a hash of the entire client bundle whenever the server detects a client-side change. This hash is published to all clients, who subscribe to it. If a client's local hash differs from the received hash, it downloads the new bundle, saves necessary data, and reloads the application (provided the reload is not denied by the app or packages).Understand the Meteor application attack surface
In a Meteor application, code running on the server is trusted, while everything from the client (including data sent via Method and publication arguments) is untrusted. Security checks must be implemented at the boundaries between these domains in three primary areas:
- Methods: Validate all incoming arguments and ensure they do not return unauthorized data.
- Publications: Validate all incoming arguments and ensure they do not return unauthorized data.
- Served files: Ensure no secret data or configuration files are served to the client.
Understand MongoDB collection types in Meteor
Meteor uses different collection behaviors depending on where they are instantiated:
- Server-side collections: Direct interfaces to the MongoDB database with a synchronous API. Operations like
insertandfindOneinteract directly with the database. - Client-side collections: These are not direct database connections but in-memory caches powered by the Minimongo library. Data is synchronized from the server via publications and subscriptions.
- Local collections: Minimongo collections with no database connection. They are used for in-memory storage on either the client or server, providing the full power of Minimongo (including reactivity and complex queries) without persisting data to MongoDB.
// Server-side or Client-side collection Todos = new Mongo.Collection('todos'); // Local collection (no database connection) SelectedTodos = new Mongo.Collection(null); // OR SelectedTodos = new Mongo.Collection('selectedtodos', {connection: null});- Server-side collections: Direct interfaces to the MongoDB database with a synchronous API. Operations like