Router.use() requires a middleware function错误提示
错误提示如下:
"D:Program FilesJetBrainsWebStorm 2017.2.4binrunnerw.exe" "D:Program Filesnodejsnode.exe" I:Developblog2app.js
I:Developblog2node_modulesexpresslibrouterindex.js:458
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^
TypeError: Router.use() requires a middleware function but got a Object
at Function.use (I:\Develop\blog2\node_modules\express\lib\router\index.js:458:13)
at Function.<anonymous> (I:\Develop\blog2\node_modules\express\lib\application.js:220:21)
at Array.forEach (<anonymous>)
at Function.use (I:\Develop\blog2\node_modules\express\lib\application.js:217:7)
at Object.<anonymous> (I:\Develop\blog2\app.js:22:5)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
进程已结束,退出代码1
**
源代码如下
**
var express = require("express");
var swig = require("swig");
var app = express();
app.use("/public",express.static(__dirname + "/public"));
app.engine("html",swig.renderFile);
app.set("views","./views");
app.set("view engine","html");
swig.setDefaults({cache:false});
//根据不同功能划分模块
app.use("/admin",require("./routers/admin"));
app.use("/api",require("./routers/api"));
app.use("/",require("./routers/main"));
app.get("/",function (req,res,next) {
// res.send("<h1>welcome</h1>");
/*
*/
res.render("index");
})
app.listen(8081);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样写没有问题,要在对应的加载文件里写module.exports = router; 谢谢,终于解决了