title: Using external function in node js route
body: <p>I'm trying to use an external function in my route which applies changes to my ejs view.</p>
  
  <p>Here is the structure of my project:</p>
  
  <pre><code>Project
      functions
          Evening.js
          Morning.js
          MyFunc.js
      routes
          about.js
          index.js
          users.js
      views
          about.ejs
          index.ejs
      app.js
  </code></pre>
  
  <p>Additionally I have my MyFunc.js:</p>
  
  <pre><code>var morning = require('./Morning');
  var evening = require('./Evening');
  
  module.exports = {
    GetMorningMessage: function () { console.log(morning); },
    GetEveningMessage: function () { console.log(evening); }
  };
  </code></pre>
  
  <p>I understand that I can use <code>app.get()</code> in my app.js to set all of the needed parameters to apply certain changes to my views, but I wonder if I can use <code>app.use()</code> in app.js and call the external functions in my routes like <code>router.get()</code>?</p>
  
  <p>For example like this <strong>(in index.js)</strong>:</p>
  
  <pre><code>var morning = welcome.GetMorningMessage();
  
  router.get('/', function (req, res) {
    res.render('index', {
      title: 'The index page!',
      h1: 'The h1',
      username: username,
      currentDate: currentDate,
      MyVar: morning
    });
  });
  </code></pre>