title: Export the result of a function in node.js
body: <p>I have written this function. What it does is reading recursively all the files into a folder thanks to nodejs module recursive-readdir. It works well.
  The problem is I don't know how to export outside <code>routes</code> array by using <code>module.exports</code>. I have tried to put it outside the callback function, inside but the variable is undefined. Any idea? </p>
  
  <pre><code>var path = require('path');
  var recursive = require('recursive-readdir');
  
  recursive(__dirname, function(err, files){
  
    var routes = {};
  
    for (var i = 0, dim = files.length; i &lt; dim; i++) {
      var file = path.basename(files[i], '.js');
      if(file !== 'bootstrap'){
        routes[file] = require(files[i]);
      }
    }
  });
  </code></pre>