报错:route.routes is not a function
来源:5-4 更合理的目录结构
杭州程序员张张
2019-10-02
为什么我这样写和老师的一样,报错
TypeError: route.routes is not a function
at fs.readdirSync.forEach.file (/Users/zhangbing/Downloads/code/zhuhu-api/app/routes/index.js:7:23)
代码如下:
const fs = require('fs')
module.exports = (app) => {
fs.readdirSync(__dirname).forEach(file => {
if (file === 'index.js') { return };
const route = require(`./${file}`);
app.use(route.routes()).use(route.allowedMethods());
})
}
目录结构
写回答
1回答
-
lewis
2019-10-02
把示例代码克隆下来可视化diff一下你和示例代码的区别。
022019-10-02
相似问题