Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor how to call a method defined in Meteor.methods()?

Tags:

meteor

I am assigning methods to a Meteor server like so:

In bootstrap.js

Meteor.startup(function () {     Meteor.methods({          foo: function () {             return 1;         },          bar: function () {          // QUESTION: HOW TO CALL Meteor.methods.foo         return 1 + foo;                  }     }); }); 
like image 814
Josh Petitt Avatar asked Apr 27 '12 01:04

Josh Petitt


People also ask

What is Meteor method?

Meteor methods are functions that are written on the server side, but can be called from the client side. On the server side, we will create two simple methods. The first one will add 5 to our argument, while the second one will add 10.

What is Meteor call?

Meteor. call() is typically used to call server-side methods from the client-side. However, you can also use Meteor. call() on the server-side to call another server-side function, though this is not recommended.

What is Meteor bindEnvironment?

bindEnvironment(func, onException, _this) import { Meteor } from 'meteor/meteor' (meteor/dynamics_nodejs.js, line 114) Stores the current Meteor environment variables, and wraps the function to run with the environment variables restored. On the server, the function is wrapped within a fiber.


1 Answers

The same way you would call bar: Meteor.call("foo");

If you are on the server and do not specify a callback the method will run synchronously.

Docs for Meteor.call: http://docs.meteor.com/#meteor_call

like image 54
greggreg Avatar answered Nov 13 '22 11:11

greggreg