title: Why is the result from one Javascript file "undefined" in the calling Javascript file?
body: <p>I have a <code>offer.js</code> file which does this:</p>
  
  <pre><code>const mssql = require('mssql/msnodesqlv8'); // mssql npm package with msnodesqlv8 for windows authentication to work
  
  
  exports.rsOffersAll = function () {
      global.MYDB.connect(function (error) {   //MYDB is a connectionPool created as a global variable in app.js
          if (error) {
              console.log(error);
              return;
          }
          global.MYDB.request(MYDB).query('SELECT Top(10) * FROM [dbo].[Offer]', function (error, result) {
              if (error) {
                  console.log(error);
              } else {
                  return(result); // I want this result to be sent to any page that asks for it
              }
              MYDB.close();
          });
      });
  };
  </code></pre>
  
  <p>I have another file called <code>index.js</code> (which will eventually be an Express controller/router) and so far I just do this:</p>
  
  <pre><code>const Offer = require('../models/offer'); // this is the `offer.js` page above
  
  var result = Offer.rsOffersAll();
  console.log(result); // this shows in the console as "undefined"
  </code></pre>
  
  <p>How do I get the <code>result</code> from <code>offer.js</code> in my <code>index.js</code> file so that I can use it? Why is it undefined? Can someone PLEASE explain it to me like I'm a 5-year old because I don't understand why such a basic thing does not work.</p>