我正在app.js中尝试此操作,因为代码封装很棒
app.use('/user',require('./routes,js')(app,mongoose,passport)
routes.js就像
module.export=(app,mongoose,passport)=>{app.post('/index',(req,res,next))}
但类型错误不断弹出
Router.use() requires a middleware function but got a undefined
答案 0 :(得分:0)
您应该从routes.js
文件中返回一些内容。您可以将routes.js
更改为:
const express = require('express');
module.exports = (app, mongoose, passport) => {
const router = express.Router();
router.post('/index', (req, res, next) => {
/* do something */
});
return router;
}