title: node.js fs.readdir doesn't show any files in directory
body: <p>I know this is probably something near to a stupid question, but I'm banging my head and I simply can't solve th problem by myself or with the help of good old google.</p>
  
  <p>I have an express 4 app in which in one route a function from a script is executed to list all available json files from a data directory.</p>
  
  <p>My directory structure is this:</p>
  
  <pre><code>/                 - app root directory with app.js
  /routes           - routes_tags.js is stored here
  /modules          - tags_list.js is stored here
  /data/rfidTagData - directory that holds json files
  </code></pre>
  
  <p>app.js requires routes_tags.js:</p>
  
  <pre><code>    var tagRoutes = require("./routes/routes_tags.js")(app);
  </code></pre>
  
  <p>routes_tags.js requires tags_list.js:</p>
  
  <pre><code>    var taglist = require('../modules/tags_list.js');
  </code></pre>
  
  <p>So app.js requires routes_tags.js which in turn requires tags_list.js in the route app.get(/tags).</p>
  
  <pre><code>    app.get("/tags", function(req, res) {
  </code></pre>
  
  <p>Below you'll see my code of tags_list.js</p>
  
  <pre><code>var path = require('path');
  var fs = require('fs');
  
  //var taglist = function(tagDirectory, serverAddr, debug){
  var taglist = function(app){
    // get global app variables
    var DEBUG = app.get('DEBUG');
    var svrAddr = app.get('svrAddr');
    var rfidTagDir = path.join('/', app.get('rfidTagDir'));
    var responseContent = '';
  
    if (DEBUG) {
      console.log('list of tags requested - provided data: ');
      console.log('directory: ' + rfidTagDir);
    }
    try {
      fs.readdir(rfidTagDir, function(err, items) {
        console.log(items);
        if (!items.length) {
          // directory appears to be empty
          console.error("nothing to read in directory "+rfidTagDir);
          responseContent = '{\'response\': \'warning\', \'message\': \'nothing to read from directory '+rfidTagDir+'\'}';
        } else {
          if (app.DEBUG) console.log(items);
          responseContent = "{\'response\': \'info\', \'description\': \'list of all stored rfid tags\', \'tags\': ["
  
          for (i in items) {
            var tag = items[i].toString().substring(0,items[i].indexOf('.'));
              responseContent += "{\'tag\': \'" + tag + "\', \'endpoint\': \'"+svrAddr+"/tags/tag/" + tag + "\', \'file\': \'"+items[i]+"\'}"
              // we only need to add the , after an array element in the json
              // structure, if there are sukzessive elements.
              if (i&lt;items.length-1) responseContent += ",";
          }
          responseContent += "]}"
        }
      });
    } catch (err) {
      console.error("could not read directory "+rfidTagDir+" to list available tags \nException output: " + err.toString());
      responseContent = '{\'response\': \'error\', \'message\': \'could not read directory '+rfidTagDir+'\', \'exception\': \' '+err.toString()+'\'}' ;
    }
  
    if (DEBUG) {console.log(responseContent)}
    return responseContent;
  }
  module.exports = taglist;
  </code></pre>
  
  <p>Now, the output is, that there is NO output albeit the fact, that I have 5 json-files in the directory rfidTagDir.</p>
  
  <p>rfidTagDir by the way is set globally in app.js as:</p>
  
  <pre><code> app.set('rfidTagDir', 'data/rfidTagData');
  </code></pre>
  
  <p>Could someone point me to my, from a professional standpoint, probably stupid error I did here? I simply can't see why it should not work.</p>
  
  <p>Best regards,</p>
  
  <p>Christian</p>
  
  <p>Ps.: You probably already know this, by I'm rather new to node.js so please excuse my rather inelegant coding style.</p>