[Solved] 'console.log' returned the value on the server but 'undefined' in the client!

I have the following code on the server :

'appEndTime': function() {
    	if(moment().day() == 5 && dayBool){
    		console.log('first')
    		dayBool = false
    		return moment().day(5 + 7).format();
    	} else if(moment().day() < 5 ){
    		dayBool = true;
    		console.log('second')
    		console.log(moment().day(7 - moment().day()).format())
    		return moment().day(7 - moment().day()).format();
    	} else if(moment().day() > 7) {
    		dayBool = true;
    		console.log('third')
    		return moment().day(moment().day() - 7).format();
    	}
    }

the code under else if(moment().day() < 5 ){ get executed and below is what is being printed to the console:
Screen Shot 2020-06-22 at 11.01.48 AM

The date is printed successfully in the server, however, when I pass it to the client and try to console.log the value, I get undefined printed in the console.

Below is how I am calling it in the client:

var endtime = Meteor.call("appEndTime", function (error, result) {
      if(error){
        console.log('endTime Error : ' + error)
      } else {
        console.log('Bingo, it worked!!');
        console.log(endtime)
      }
    });
    console.log(endtime)

Below is the result found on the client:
Screen Shot 2020-06-22 at 11.18.07 AM

How can I get the value in the client in the same format as it is in the server.

Meteor.call("appEndTime", function (error, endtime) {
  if (error) {
    console.log('endTime Error : ' + error);
  } else {
    console.log('Bingo, it worked!!');
    console.log(endtime);
  }
});

The result is returned in the callback, not as the return value of the Meteor.call.

1 Like

That you, it worked!

1 Like