title: TypeError: Router.use() requires middleware function but got a Object IN Node js
body: <p>I am getting this error while setting up app on my localhost. "Router.use() requires middleware function but got a Object".
   Please take a look to solve this problem. </p>
  
  <pre><code>../master/node_modules/express/lib/router/index.js:458
        throw new TypeError('Router.use() requires middleware function but got a
              ^
  TypeError: Router.use() requires middleware function but got a Object
      at Function.use (/home/divine20/master/node_modules/express/lib/router/index.js:458:13)
      at EventEmitter.&lt;anonymous&gt; (/home/divine20/master/node_modules/express/lib/application.js:219:21)
      at Array.forEach (native)
      at EventEmitter.use (/home/divine20/master/node_modules/express/lib/application.js:216:7)
      at Object.exports.default (/home/divine20/master/server/routes.js:25:7)
      at Object.&lt;anonymous&gt; (/home/divine20/master/server/app.js:34:2)
      at Module._compile (module.js:456:26)
  </code></pre>
  
  <p>My app.js File.</p>
  
  <pre><code> 'use strict';
  
   import express from 'express';
   import mongoose from 'mongoose';
   mongoose.Promise = require('bluebird');
   import config from './config/environment';
   import http from 'http';
  
   // Connect to MongoDB
   mongoose.connect(config.mongo.uri, config.mongo.options);
   mongoose.connection.on('error', function(err) {
       console.error('MongoDB connection error: ' + err);
       process.exit(-1);
   });
  
   // Populate databases with sample data
   if (config.seedDB) {
       require('./config/seed');
   }
  
   // Setup server
   var app = express();
   var server = http.createServer(app);
   var socketio = require('socket.io')(server, {
       serveClient: config.env !== 'production',
       path: '/socket.io-client'
   });
   require('./config/socketio').default(socketio);
   require('./config/express').default(app);
   require('./routes').default(app);
  
   // Start server
   function startServer() {
       app.angularFullstack = server.listen(config.port, config.ip, function() {
           console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
       });
   }
  
   setImmediate(startServer);
  
   // Expose app
   exports = module.exports = app;
  </code></pre>
  
  <p><strong>my routes.js file.</strong></p>
  
  <pre><code>'use strict';
  
  import errors from './components/errors';
  import path from 'path';
  import aws from './api/config/aws.js';
  
  export default function(app) {
      // Insert routes below
      app.use('/api/reports', require('./api/report'));
      app.use('/api/utilities', require('./api/utility'));
      app.use('/api/mails', require('./api/mail'));
      app.use('/api/repayments', require('./api/repayment'));
      app.use('/api/transactions', require('./api/transaction'));
      app.use('/api/offers', require('./api/offer'));
      app.use('/api/payments', require('./api/payment'));
      app.use('/api/yelp', require('./api/yelp'));
      app.use('/api/blogs', require('./api/blog'));
      app.use('/api/faqs', require('./api/faq'));
      app.use('/api/blog', require('./api/blog'));
      app.use('/api/listings', require('./api/listing'));
      app.use('/api/users', require('./api/user'));
      app.get('/api/s3Policy', aws.getS3Policy);
      app.post('/api/uploadToS3', aws.uploadToS3);
  
      app.use('/auth', require('./auth'));
  
      // All undefined asset or api routes should return a 404
      app.route('/:url(api|auth|components|app|bower_components|assets)/*')
          .get(errors[404]);
  
      // All other routes should redirect to the index.html
      app.route('/*')
          .get((req, res) =&gt; {
              res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
          });
  }
  </code></pre>
  
  <p>There is an Index.js under auth folder where <strong>express.Router()</strong> has been used.</p>
  
  <pre><code>'use strict';
  
  import express from 'express';
  import passport from 'passport';
  import config from '../config/environment';
  import User from '../api/user/user.model';
  
  // Passport Configuration
  require('./local/passport').setup(User, config);
  require('./facebook/passport').setup(User, config);
  require('./google/passport').setup(User, config);
  
  var router = express.Router();
  
  router.use('/local', require('./local'));
  router.use('/facebook', require('./facebook'));
  router.use('/google', require('./google'));
  
  export default router;
  </code></pre>