juanp_1982
juanp_1982

Reputation: 1007

how to execute a server script and then pass the information to the client in meteor

I'm working with two files [root]/test.js with a calling function

Meteor.call("getUsers", "Juan P", function (error, result) {
           console.log(result);
      });

and another file [root]/server/secret.js with this definition

if (Meteor.isServer) {
      var getUsers = function(name) {
           return "Hi. I'm " + name;
      };
}

however the function getUsers is getting undefined, I really appreciate any help or hint about fixing this problem! :-)

Upvotes: 0

Views: 67

Answers (2)

Łukasz Gozda Gandecki
Łukasz Gozda Gandecki

Reputation: 364

You have to define it as a Meteor.method

Meteor.methods({
    getUsers: function (name) {
       return "Hi. I'm " + name;
    }
});

Also, when you put your code in /server/ folder you don't have to check Meteor.isServer anymore, it makes it a little cleaner. Same goes for /client/ and Meteor.isClient.

Upvotes: 3

none
none

Reputation: 1817

Look at this:

Meteor.methods({
  getUsers: function (name) {
    return "Hi. I'm " + name;
  }
});

And you don't need isServer, because everything in folder server runs on the server.

Upvotes: 1

Related Questions