title: How to get a class with a unknown name with require()
body: <p>I have a template class file called</p>
  
  <p><code>./templates/Class.js</code></p>
  
  <pre class="lang-js prettyprint-override"><code>class Template {
  //code
  }
  </code></pre>
  
  <p>Then I have another class called:</p>
  
  <p><code>./classes/Foo.js</code></p>
  
  <pre class="lang-js prettyprint-override"><code>const Template = require('./../../templates/Class.js')
  class Foo extends Template {
  //code
  }
  </code></pre>
  
  <p>I have a main file called: <code>./index.js</code>, which checks all files under <code>./classes/</code>, and checks if it's a </p>
  
  <pre class="lang-js prettyprint-override"><code>classname instanceof Template;
  </code></pre>
  
  <p>So I can't keep track of all the classnames under <code>./classes/</code>, and I want to require all files under <code>./classes/</code>, check for any classes for each file that extends off of my <code>Template</code> class, and add that class/function to a map. I know how to require all files under <code>./classes/</code> but not much after that, so how do I do that?</p>
  
  <p>HOW I REQUIRE FILES:
  <code>index.js</code></p>
  
  <pre class="lang-js prettyprint-override"><code>const getAllFiles = function(dirPath, arrayOfFiles) {
    files = fs.readdirSync(dirPath)
  
    arrayOfFiles = arrayOfFiles || []
  
    files.forEach(function(file) {
      if (fs.statSync(dirPath + "/" + file).isDirectory()) {
        arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
      } else {
        if(fs.readdirSync(dirPath).filter(file =&gt; file.endsWith('.js') &amp;&amp; fs.statSync(dirPath + "/" + file).isFile()).length) {
        arrayOfFiles.push(dirPath + "/" + file)
        }
      }
    })
  
    return arrayOfFiles;
  };
  </code></pre>