Router.use() requires middleware function but got a undefined
because you are exporting module with a function inside so you need to return your router at the end of your function at division_model.js
return router;
this should work
You must return a router in your middleware here:
app.use('/division', division_model);
So, your module export function should end with:
return router;
You also have conflicting ideas when setting this up. If you want the app to define the route as /division which you do here:
app.use('/division', division_model);
then you do not need to redefine the route again like you do here:
var router = express.Router();
router.route('/division');
You can simply:
app.use(division_model);
-- or --
/**
* division_model.js
*/
var router = express.Router();
router.route('/');
//omitting route code
router.route('/:division_id');
//omitting route code
return router;
/**
* server.js
*/
app.use('/division', division_model);