Why are Meteor methods included in the models.js file?

According to this video, meteor methods must be defined in the models.js file, which is available on the client and on the server.

If methods should be safe procedures that the client invokes on the server, why are they defined in the models.js file? Clients call methods with Meteor.call, so it makes no sense to define our methods on the server, and not in models.js?

+6
source share
2 answers

You do not need to put the methods in the "model.js" file, you can put them anywhere, they just called the model.js file in the video.

Meteor.methods is the Anywhere method, which means that it can exist both on the server and on the client. If you look at the documents , you will see the explained difference:

Call methods on the server define functions that clients can call remotely.

[...]

Call methods on the client define stub functions associated with server methods of the same name.

In the video, they show you a demonstration of how the methods and other functions of Meteor work, so they were not related to the specific placement of methods on the server.

+2
source

The video you post is just a teaser about what Meteor can do. This is not a textbook. The documentation explains how the methods work. For customers, the method will only be outlined.

If you make the method available only on the server, this method will not be skipped. You should also read the concepts of Meteor.

0
source

All Articles