title: Node.js get the return value of a function
body: <p>I just started working on node.js and getting to know its concepts, I am having a little trouble understanding callbacks,what I am trying to do is call function <strong><em>getUserBranch()</em></strong> in the function <strong><em>getOffers()</em></strong>.</p>
  
  <p>I read that because of node.js async nature its better to use a callback function to get the desired data once the complete execution is done.</p>
  
  <p>Now I am having trouble retrieving the value that <strong><em>getUserBranch</em></strong> is returning,I have no proper idea how to do it, well the callback function has the value but how do I get the value from there?</p>
  
  <p><em>file2.js</em></p>
  
  <pre><code>var getUserBranch = function(email,callback) {
  
  
  client.execute('SELECT * from branch WHERE email=?', [ email ], function(
          err, data, fields) {
      if (err)
  
          console.log("error");
      else
          console.log('The solution is in branch: \n', data);
      res = data.rows[0];
      return callback(res);
  });
  
  }
  </code></pre>
  
  <p><em>file1.js</em></p>
  
  <pre><code>var getOffers = function (email) {
  
     var branchObj = require('./file2.js');
     var branchList = branchObj.getUserBranch(email,getList));
     return branchList;
  };
  
  var getList = function(res){
    var results=res;
    return results;
  }
  </code></pre>