title: Problem using async functions in NodeJs middleware
body: <p>I am running into an issue when I try to load the initial data for my blacklist from a Redis DB in my middleware code. Since the DB request takes some time it starts to fail.</p>
  <p>Below is my code which gets fired when app starts via <code>app.use(blacklist.blockRequests());</code>.</p>
  <p>When I try to make the function async I get the error that <code>new TypeError('app.use() requires a middleware function')</code>.</p>
  <p>One of the side effects is also that my array is empty when it's called again.</p>
  <pre><code>blockRequests: function() {
    this.read();
    this.logEvent('info', 'There are ' + this.blacklist.length + ' address(es) on the blacklist');
    var self = this;
  
    var interceptor = function(request, response, next) {
      var ip = request.headers['x-forwarded-for'] || request.connection.remoteAddress;
  
      if (self.isInBlacklist(ip)) {
        self.logEvent('warn', 'Rejecting request from ' + ip + ', path and query was ' + request.originalUrl);
        response.status(403).send();
      } else {
        next();
      }
    }
  
    return interceptor;
  },
  </code></pre>
  <p>And here is my <code>read()</code> function code:</p>
  <pre><code>read: function() {
    try {
      // get all records with prefix block:: from redis
      redis.redis.keys('block::*', function (err, reply) {
        // reply is null when the key is missing
        if(err){}
        else {
          this.blacklist = []
  
          for (let i = 0; i &lt; reply.length; i++) {
            let ipInt = reply[i].substring(7)
            let ipStr = ipToInt(ipInt).toIP()
            this.blacklist.push(ipStr)             
          }
        }   
      });
    } catch (error) {
      if (error) {
        this.blacklist = [];
      }
    }
  }
  </code></pre>