Core
Documentation of core Meteor functions.
Anywhere
Meteor.isClient
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 31)
Boolean variable. True if running in client environment.
Anywhere
Meteor.isServer
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 39)
Boolean variable. True if running in server environment.
Meteor.isServer
can be used to limit where code runs, but it does notprevent code from being sent to the client. Any sensitive code that youdon’t want served to the client, such as code containing passwords orauthentication mechanisms, should be kept in theserver
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 23)
Boolean variable. True if running in development environment.
Anywhere
Meteor.isProduction
import { Meteor } from 'meteor/meteor' (meteor/client_environment.js, line 15)
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
- funcFunction
- A function to run on startup.
On a server, the function will run as soon as the server process isfinished starting. On a client, the function will run as soon as the DOMis ready. Code wrapped in Meteor.startup
always runs after all appfiles have loaded, so you should put code here if you want to accessshared variables from other files.
The startup
callbacks are called in the same order as the calls toMeteor.startup
were made.
On a client, startup
callbacks from packages will be calledfirst, 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(() => {
if (Rooms.find().count() === 0) {
Rooms.insert({ name: 'Initial room' });
}
});
}
Anywhere
Meteor.wrapAsync(func, [context])
import { Meteor } from 'meteor/meteor' (meteor/helpers.js, line 89)
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
- funcFunction
A function that takes a callback as its final parameter
contextObject
- Optional
this
object against which the original function will be invoked
Anywhere
Meteor.defer(func)
import { Meteor } from 'meteor/meteor' (meteor/timers.js, line 84)
Defer execution of a function to run asynchronously in the background (similar to Meteor.setTimeout(func, 0)
.
Arguments
- funcFunction
- 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
- pathString
- A path to append to the root URL. Do not include a leading "
/
".
Options
- secureBoolean
Create an HTTPS URL.
replaceLocalhostBoolean
Replace localhost with 127.0.0.1. Useful for services that don't recognize localhost as a domain name.
rootUrlString
- 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 76)
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.