http://docs.meteor.com/#meteor_methods
I have tried it in publish.js in my server folder.
I am successfully calling Meteor.apply and attempting the server call from the client. I always get an undefined response.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Calling
Meteor.methodson the server is correct. That will define remote methods that run in the privileged environment and return results to the client. To return a normal result, just callreturnfrom your method function with some JSON value. To signal an error, throw aMeteor.Error.On the client,
Meteor.applyalways returnsundefined, because the method call is asynchronous. If you want the return value of the method, the last argument toapplyshould be a callback, which will be passed two arguments:errorandresult, in the typical async callback style.Is your server code actually getting called? You can check that by updating the DB in the method and seeing if the client’s cache gets the new data, or calling
console.logfrom inside the method body and looking at the output of the “meteor” process in your terminal.