So, a few problems:
- BLOCKING!Â
That's your main issue. Your while() loop with dates is blocking your entire app server. It's not like say, PHP where each request gets its own instance of a PHP script. Here, one app, one script handles all requests. So when you block with while loop, you block all requests and that's why your second request is delayed. It's actually executed immediately, but immediately after it's been received. Which is after all those milions of while loop spins.
That's a very bad practice. You'll also probably notice that your CPU is at 100% during your long requests.
How to remedy it? Use setTimeout.
So, your userRepository would do something like this:
   getUsers: function(long, callback) {
  Â
     if(!long) {
       db.users.find({}, function(err, usersList) {
         Â
         callback(err, usersList);
       });
     } else {
       setTimeout(function() {
         db.users.find({}, function(err, usersList) {
         Â
           callback(err, usersList);
         });
       }, 5000);
    }
  }
Your second issue is method signature, like somebody has mentioned already. Your callbacks will usually be the LAST parameter to the request handlers. Also, in the callback, you will usually pass err or null as the first argument. Say that your db is down - you will want to pass that info and your render('index') might look like render('db-error'); instead.