title: Router.use() requires middleware function but got a Object
body: <p>After I have added a route to my express handler, I am getting an error (see below):</p>
  
  <pre><code>/app/node_modules/express/lib/router/index.js:458
  2017-01-03T15:53:48.842543+00:00 app[web.1]:       throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn));
  2017-01-03T15:53:48.842545+00:00 app[web.1]:       ^
  2017-01-03T15:53:48.842545+00:00 app[web.1]: 
  2017-01-03T15:53:48.842546+00:00 app[web.1]: TypeError: Router.use() requires middleware function but got a Object
  2017-01-03T15:53:48.842547+00:00 app[web.1]:     at Function.use (/app/node_modules/express/lib/router/index.js:458:13)
  2017-01-03T15:53:48.842548+00:00 app[web.1]:     at EventEmitter.&lt;anonymous&gt; (/app/node_modules/express/lib/application.js:219:21)
  2017-01-03T15:53:48.842549+00:00 app[web.1]:     at Array.forEach (native)
  2017-01-03T15:53:48.842549+00:00 app[web.1]:     at EventEmitter.use (/app/node_modules/express/lib/application.js:216:7)
  2017-01-03T15:53:48.842550+00:00 app[web.1]:     at module.exports (/app/server/routes/index.js:16:9)
  2017-01-03T15:53:48.842551+00:00 app[web.1]:     at Object.&lt;anonymous&gt; (/app/server.js:59:27)
  2017-01-03T15:53:48.842551+00:00 app[web.1]:     at Module._compile (module.js:556:32)
  2017-01-03T15:53:48.842552+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:565:10)
  2017-01-03T15:53:48.842553+00:00 app[web.1]:     at Module.load (module.js:473:32)
  2017-01-03T15:53:48.842553+00:00 app[web.1]:     at tryModuleLoad (module.js:432:12)
  2017-01-03T15:53:48.842554+00:00 app[web.1]:     at Function.Module._load (module.js:424:3)
  2017-01-03T15:53:48.842554+00:00 app[web.1]:     at Module.runMain (module.js:590:10)
  2017-01-03T15:53:48.842555+00:00 app[web.1]:     at run (bootstrap_node.js:394:7)
  2017-01-03T15:53:48.842556+00:00 app[web.1]:     at startup (bootstrap_node.js:149:9)
  2017-01-03T15:53:48.842556+00:00 app[web.1]:     at bootstrap_node.js:509:3
  </code></pre>
  
  <p>This is the my index.js for routing (just a part of it):</p>
  
  <pre><code>module.exports = function(app) {
  ...
      app.use('/api/elasticsearch', require('../elasticsearch'));
  ...
  </code></pre>
  
  <p>And here the index.js in folder "elasticsearch":</p>
  
  <pre><code>var express = require('express');
  var controller = require('./elasticsearch.controller');
  var router = express.Router();
  
  router.post('/index', controller.writeIndex);
  
  module.exports = router;
  </code></pre>
  
  <p>Here is the start of the "writeIndex" function within the controller, I do not see any errors there as well:</p>
  
  <pre><code>exports.writeIndex = function (req, res) {
  ..
  }
  function indexData(technicians,indexName, typeName) {
  ..
  }
  ..
  </code></pre>
  
  <p>I am using HEROKU, and I did not have any problems before.
  I think the main error here is: </p>
  
  <pre><code>throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn));
  </code></pre>
  
  <p>but what does it mean?</p>
  
  <p>Here is my directory structure of my project (just a part of it to be readable):</p>
  
  <pre><code>- server
  -- elasticsearch
  -- index.js
  -- elasticsearch.controller.js
  - routes
  -- index.js
  - api
  -- coresystems
  -- coresystems.controller.js
  -- coresystemsAPI.js
  -- index.js
  </code></pre>