title: NodeJS - how to return arrays from a module
body: <p>I've got a module called 'userinfo.js' retrieving info about users from DB. Here's the code:</p>
  
  <pre><code>exports.getUserInfo = function(id){
  db.collection("users", function (err, collection) {
      var obj_id = BSON.ObjectID.createFromHexString(String(id));
      collection.findOne({ _id: obj_id }, function (err, doc) {
          if (doc) {
              var profile = new Array();
              profile['username']=doc.username;
              return profile;
          } else {
              return false;
          }
      });
  });
  }
  </code></pre>
  
  <p>From index.js (controller for index page, from which I'm trying to access userinfo) in a such way:</p>
  
  <pre><code>var userinfo = require('../userinfo.js');
  
  var profile = userinfo.getUserInfo(req.currentUser._id);
  console.log(profile['username']);
  </code></pre>
  
  <p>Node returns me such an error:</p>
  
  <pre><code>console.log(profile['username']);   --&gt;     TypeError: Cannot read property 'username' of undefined
  </code></pre>
  
  <p>What I'm doing wrong? Thanks in advance!</p>