TypeError: Router.use () requires middleware function but gets object in Express 4.13.1

This is how it is configured in my 4.13.1 express app

index.js

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});

module.exports = router;
-------------------------------------
app.js 

var routes = require('./routes/index');
app.use('/', routes);
app.use('api/users', users);

      

Even after this configuration, it still throws an error. any ideas?

   /home/vagrant/portal-api/portal-api/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/vagrant/portal-api/portal-api/node_modules/express/lib/router/index.js:458:13)
    at EventEmitter.<anonymous> (/home/vagrant/portal-api/portal-api/node_modules/express/lib/application.js:219:21)
    at Array.forEach (native)
    at EventEmitter.use (/home/vagrant/portal-api/portal-api/node_modules/express/lib/application.js:216:7)
    at Object.<anonymous> (/home/vagrant/portal-api/portal-api/app.js:31:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

      

+3


source to share





All Articles