1.1 KiB
{{#template name="basicEnvironment"}}
Environment
{{> autoApiBox "Meteor.isClient"}} {{> autoApiBox "Meteor.isServer"}}
{{#note}}
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.
{{/note}}
{{> autoApiBox "Meteor.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 page is ready.
It's good practice to wrap all code that isn't inside template events, template
helpers, methods, publish, or subscribe in Meteor.startup so that your
application code isn't executed before the environment is ready.
Example:
// 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"});
}
});
}
{{/template}}