Core

Documentation of core Meteor functions.

Anywhere
Meteor.isClient
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 30)

Boolean variable. True if running in client environment.

Anywhere
Meteor.isServer
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 38)

Boolean variable. True if running in server environment.

Meteor.isServer can be used to limit where code runs, but it does not prevent code from being sent to the client. Any sensitive code that you don’t want served to the client, such as code containing passwords or authentication mechanisms, should be kept in the server directory.

Anywhere
Meteor.isCordova
import { Meteor } from 'meteor/meteor' (meteor/cordova_environment.js, line 7)

Boolean variable. True if running in a Cordova mobile environment.

Anywhere
Meteor.isDevelopment
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 22)

Boolean variable. True if running in development environment.

Anywhere
Meteor.isProduction
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 14)

Boolean variable. True if running in production environment.

Anywhere
Meteor.startup(func)
import { Meteor } from 'meteor/meteor' (meteor/startup_client.js, line 70)

Run code when a client or a server starts.

Arguments

func Function

A function to run on startup.

On a server, the function will run as soon as the server process is finished starting. On a client, the function will run as soon as the DOM is ready. Code wrapped in Meteor.startup always runs after all app files have loaded, so you should put code here if you want to access shared variables from other files.

The startup callbacks are called in the same order as the calls to Meteor.startup were made.

On a client, startup callbacks from packages will be called first, followed by <body> templates from your .html files, followed by your application code.

// On server startup, if the database is empty, create some initial data.

if (Meteor.isServer) {
  Meteor.startup(function () {
    if (Rooms.find().count() === 0) {
      Rooms.insert({name: "Initial room"});
    }
  });
}

Anywhere
Meteor.wrapAsync(func, [context])
import { Meteor } from 'meteor/meteor' (meteor/helpers.js, line 90)

Wrap a function that takes a callback function as its final parameter. The signature of the callback of the wrapped function should be function(error, result){}. On the server, the wrapped function can be used either synchronously (without passing a callback) or asynchronously (when a callback is passed). On the client, a callback is always required; errors will be logged if there is no callback. If a callback is provided, the environment captured when the original function was called will be restored in the callback.

Arguments

func Function

A function that takes a callback as its final parameter

context Object

Optional this object against which the original function will be invoked

Anywhere
Meteor.defer(func)
import { Meteor } from 'meteor/meteor' (meteor/timers.js, line 74)

Defer execution of a function to run asynchronously in the background (similar to Meteor.setTimeout(func, 0).

Arguments

func Function

The function to run

Anywhere
Meteor.absoluteUrl([path], [options])
import { Meteor } from 'meteor/meteor' (meteor/url_common.js, line 10)

Generate an absolute URL pointing to the application. The server reads from the ROOT_URL environment variable to determine where it is running. This is taken care of automatically for apps deployed to Galaxy, but must be provided when using meteor build.

Arguments

path String

A path to append to the root URL. Do not include a leading "/".

Options

secure Boolean

Create an HTTPS URL.

replaceLocalhost Boolean

Replace localhost with 127.0.0.1. Useful for services that don't recognize localhost as a domain name.

rootUrl String

Override the default ROOT_URL from the server environment. For example: "http://foo.example.com"

Anywhere
Meteor.settings
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 49)

Meteor.settings contains deployment-specific configuration options. You can initialize settings by passing the --settings option (which takes the name of a file containing JSON data) to meteor run or meteor deploy. When running your server directly (e.g. from a bundle), you instead specify settings by putting the JSON directly into the METEOR_SETTINGS environment variable. If the settings object contains a key named public, then Meteor.settings.public will be available on the client as well as the server. All other properties of Meteor.settings are only defined on the server. You can rely on Meteor.settings and Meteor.settings.public being defined objects (not undefined) on both client and server even if there are no settings specified. Changes to Meteor.settings.public at runtime will be picked up by new client connections.

Anywhere
Meteor.release
import { Meteor } from 'meteor/meteor' (meteor/helpers.js, line 11)

Meteor.release is a string containing the name of the release with which the project was built (for example, "1.2.3"). It is undefined if the project was built using a git checkout of Meteor.

© 2011–2017 Meteor Development Group, Inc.
Licensed under the MIT License.
https://docs.meteor.com/v1.3.5/api/core.html