title: return results from a function (javascript, nodejs)
body: <p>Could anyone help me with this code? I need to return a value form a routeToRoom function:</p>
  
  <pre><code>var sys = require('sys');
  
  function routeToRoom(userId, passw) {
      var roomId = 0;
      var nStore = require('nstore/lib/nstore').extend(require('nstore/lib/nstore/query')());
      var users = nStore.new('data/users.db', function() {
  
          users.find({
              user: userId,
              pass: passw
          }, (function(err, results) {
              if (err) {
                  roomId = -1;
              } else {
                  roomId = results.creationix.room;
              }
          }
          ));
      });
      return roomId;
  }
  sys.puts(routeToRoom("alex", "123"));
  </code></pre>
  
  <p>But I get always: 0</p>
  
  <p>I guess <code>return roomId;</code> is executed before <code>roomId=results.creationix.room</code>. Could someone help me with this code?</p>