Core
If you prefer to watch the video, click below.
Meteor.isClient
Boolean variable. True if running in client environment.
Meteor.isServer
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 theserver
directory.
Meteor.isCordova
Boolean variable. True if running in a Cordova mobile environment.
Meteor.isDevelopment
Boolean variable. True if running in development environment.
Meteor.isProduction
Boolean variable. True if running in production environment.
Meteor.startup(func)
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(() => {
if (Rooms.find().count() === 0) {
Rooms.insert({ name: 'Initial room' });
}
});
}
Meteor.wrapAsync(func, [context])
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.
The parameters of the wrapped function must not contain any optional parameters or be undefined, as the callback function is expected to be the final, non-undefined parameter.
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
Defer execution of a function to run asynchronously in the background (similar to Meteor.setTimeout(func, 0)
.
Arguments
- func Function
-
The function to run
Meteor.absoluteUrl([path], [options])
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
"
Meteor.settings
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.
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.
Meteor.isModern
Boolean variable. True if running in a "modern" JS
environment, as determined by the modern
package.
Meteor.gitCommitHash
Hexadecimal Git commit hash, if the application is using Git for version control. Undefined otherwise.
Boolean variable. True when running unit tests (false if running tests in full app mode).
Meteor.isAppTest
Boolean variable. True if running tests against your application i.e meteor test --full-app
.
Meteor.isPackageTest
Boolean variable. True if running tests against a Meteor package.