title: How to automatically include all js files inside the html of an express application?
body: <p>I feel completely stupid trying to use node...</p>
  
  <p>I'm using Node.JS with express. I want to automatically include all my client JS scripts into my HTML page. This is extremely straight-forward in the other languages I know (PHP or C#), but I can't get it to work...</p>
  
  <p>I've tried doing it using glob directly in the ejs file:</p>
  
  <p>views/partials/footer.ejs:</p>
  
  <pre><code>&lt;% glob(path.join(dir, "../public/js/**/*.js"), function(er, files){
      files.forEach(function(file){
      %&gt;
  &lt;script src="&lt;%=file %&gt;" &gt;&lt;/script&gt;
  &lt;%
  });
  });
   %&gt;
  </code></pre>
  
  <p>routes/index.js:</p>
  
  <pre><code>var express = require('express');
  var glob = require('glob');
  var path = require('path');
  var router = express.Router();
  
  /* GET home page. */
  router.get('/', function(req, res, next) {
  
    res.render('index', {
          title: 'Express',
          glob: glob,
          path: path,
          dir: __dirname
    });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>The code runs, and the partial file is included (if I place text inside, I see it). But when this code runs, it add no files, even though there are definitely files in that directory (public/app/module.js for example).</p>
  
  <p>It seems to me that this is something very basic, but I haven't found anyone asking about it, and no easy way to do it. It seems very critical, especially for frameworks which require many files, such as angular.</p>
  
  <p>What is the right way to do this with angular, and why didn't this work?</p>