Chaining methods, but detecting if called from server


Sometimes I want to chain meteor methods where

  • the initial method comes from the client
  • subsequent methods are called from the server

I want the subsequent methods to not be called from the client e.g.

if (this.connection) {
  throw new Meteor.Error('called-from-client', 'Error')

But, if the initial method is called then connection is still defined.

// Client'firstMethod');

// Server

  firstMethod: function () {'serverOnlyMethod');

  serverOnlyMethod: function() {
    // throw error if called from client


Has anyone found a way to distinguish?


Why would you want to call a method from the server?

Meteor methods are the way for the client to communicate with the server. So I don’t see a reason why you should do a method call from somewhere in the server.


To allow code to run asynchronously.


@themeteorchef posted a snippet related to this a while back that might help: Preventing Client Calls to a Server-Only Method