title: Node\Express - "TypeError: require(...) is not a function" or app is undefined
body: <p>I keep getting this error message after refactoring my code into separate js files. I have tried numerous different methods based on SO posts but nothing seems to work, I either get this error or the app variable is <code>undefined</code> in my controller.</p>
  
  <p>I am a complete Node novice so if someone can point me in the right direction I would be very grateful!</p>
  
  <p>Node  version: v6.17.0</p>
  
  <p>app.js</p>
  
  <pre><code>const express = require('express');
  const app = express();
  const controller = require('./plate-controller');
  
  module.exports.app = app;
  </code></pre>
  
  <p>controller</p>
  
  <pre><code>const plateService = require('./plate-service');
  
  var app = require('./app').app;
  var exports = module.exports = {};
  
  exports.controller = function(app) {
      app.get('/plates/:plate_id', function (req, res) {
          return plateService.getPlateById(req, res);
      });
  
      app.get('/plates/search/:plate', function (req, res) {
          return plateService.search(req, res);
      });
  
      app.get('/plates/current-plates', function (req, res) {
          return plateService.getCurrentPlates(req, res);
      });
  
      app.get('plates/prefix-plates', function (req, res) {
          return plateService.getPrefixPlates(req, res);
      });
  };
  </code></pre>
  
  <p>This gives undefined and trying to call like <code>require('..')()</code> always give the <code>is not a function</code> error.</p>
  
  <p>When printing out the controller variable to the console it actually doesnt look as I thought it would, a function, rather its a function inside an object so I suppose that is the cause of the <code>require(...) is not a function</code>.</p>
  
  <p><code>{ controller: [Function] }</code></p>