Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Meteor methods go in the models.js file?

Tags:

meteor

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

If methods are supposed to be secure procedures that the client invokes on the server, why are they defined in the models.js file? Clients call methods with Meteor.call, so doesn't it make sense to define our methods on the server, not in models.js?

like image 682
Charles Holbrow Avatar asked Feb 27 '13 15:02

Charles Holbrow


1 Answers

You don't have to put methods in a "model.js" file, you can put them anywhere, they just happened to name the file model.js in the video.

Meteor.methods is an "Anywhere" method, which means that it can exist on both the server and the client. If you look at the docs, you'll see the difference explained:

Calling methods on the server defines functions that can be called remotely by clients.

[...]

Calling methods on the client defines stub functions associated with server methods of the same name.

In the video they're showing you a demo of how methods and other features of Meteor work, so they weren't concerned with specifically placing the methods in the server.

like image 134
Rahul Avatar answered Oct 20 '22 14:10

Rahul