title: Reading all files in a directory
body: <p>here is the code snippet of what I am working with right now...</p>
  
  <pre><code>/* 
      Module: inputReader.js, directoryScanner.js (included)
      Description: Basic file reader returns string of contents of a file from a set file name
      Needs to be done: Add key listener to allow for a dynamic file name
   */
  
  // Declare node.js module dependencies from API
  var fs = require('fs'), 
      wrench = require('wrench'),
      util = require('util')
  
  // Define module to be exported as a function(s)
  module.exports = {
      dirRead: function() {
          var rootfolder = './node_modules';
          var filteredfiles = [];
          var files = [];
          var fileextension = '.html';
  
          files = wrench.readdirSyncRecursive(rootfolder)
          for (var i = 0; i&lt;files.length; i++) { 
              if (files[i].indexOf(fileextension) != -1) { 
                  filteredfiles.push(files[i]);
              }
          }
          return filteredfiles;
      },
  
      fileRead: function() {
          // Call synchronous fileSystem function readFileSync on file name
          for(i = 0; i&lt;filteredfiles.length; i++) {
              var temp = fs.readFileSync(filteredfiles[i].toString(), 'utf8')
              return temp
          }
      }
  };
  </code></pre>
  
  <p>I am exporting a module of 2 different functions; the first (readDir) that reads a directory and its' subdirectories for a list of files and the second (readFile) which relies on the first (reads the list of files from the first function and actually goes through each file).</p>
  
  <p>The problem is when I try to call that look of filteredfiles in the 2nd function, readFile, I get an error saying filteredfiles is undefined.</p>
  
  <p>I am not sure how to fix this, may someone help me please? (My guess is a scope problem)...</p>
  
  <pre><code>res.send(reader.dirRead()) and then, res.send(reader.fileRead(reader.dirRead()))
  </code></pre>