title: How do I return a valid response from an asynchronous method using Express?
body: <p>Still getting the hang of Node's non-blocking nature.  The following code executes as intended. However, I am wondering if there is a better approach to accomplish the task.  </p>
  
  <p>There are 3 params being supplied to the route (zipcode, type, rad).
  From there I use the NPM Zipcode package to return an array of zipcodes within the provided rad. </p>
  
  <p>I am then using a for loop on the zips array within an async function and awaiting the response of a function which performs a MySQL query and returns a promise. Then returning an array of user objects. </p>
  
  <p>My uncertainty is whether I am sending the response correctly or if there is a more efficient way to write this code. </p>
  
  <p>Thanks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>router.get('/:zipcode/:type/:rad', function (req, res) {
  
    const rad = req.params.rad;
    const zip = req.params.zipcode;
    let zips = zipcodes.radius(zip, rad);
    zips.push(zip);
  
    let type;
    if(req.params.type === 'bartenders') {
      type = 0;
    } else {
      type = 1;
    }
  
    const params = {
      'type': type,
      'zips': zips
    };
  
  
    function userGroup(type, zip) {
      return new Promise(resolve =&gt; {
        connection.query(`SELECT * FROM bt9.users WHERE zip = ${zip} AND type = ${type} AND display = 1`, function (err, result) {
          if(err) throw err;
          resolve(result);
        });
      });
    }
  
  
    async function getUsers(params) {
      let userList = [];
      for (i = 0; i &lt; params.zips.length; i++) {
        const users = await userGroup(params.type, params.zips[i]);
        for (u = 0; u &lt; users.length; u++) {
          userList.push(users[u]);
        }
      }
      return userList;
    }
  
  
    function sendUsers(callback) {
      getUsers(params).then( res =&gt; {
        callback(null, res)
      })
    }
  
  
    sendUsers(function(err, result) {
      if(err) throw err;
      res.send(result)
    })
  
  
  });</code></pre>
  </div>
  </div>
  </p>