Q:

passing value server to client in method meteor

client side code 
Template.hello.events({
 "click": function () {
  Meteor.call('Message',function(result){
  alert(result);
 });

server side method call
if (Meteor.isServer) {

Meteor.methods({
 'Message':function(){
 SerialPort.list(function (err, ports) {

 ports.forEach(function(port) {
 console.log(port.comName);  
  var atxt =  port.comName;
  return atxt ;
 });//ports end
 });  //list end
 }   //message end
 }); //method end
 }   //server end

The above programme 'undefined' print the alert box client side . return atxt not returned any value. please help me meteor apllication passing server side return value access the client side !!! 

A:

when Meteor server side methods returns some data, client side need to fetch that asynchronously via a callback. And in that callback, there need to have two parameters, error and result. Basically the second parameter is your result and the first one is error (if any). So, you need to update your client side code accordingly. Besides before returning from server side ,just console.log your data so that you can be sure of the result.
Meteor.call('Message',function(err,result){
    if(!err) {
        alert(result);
    } else {console.log(err);}
});

