作者:lululove8_530 | 来源:互联网 | 2023-07-27 23:39
错误提示如下:
"D:Program FilesJetBrainsWebStorm 2017.2.4binrunnerw.exe" "D:Program Filesnodejsnode.exe" I:Developblog2app.js
I:Developblog2node_modulesexpresslibrouterindex.js:458
1 2
| 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
1 2 3 4 5 6 7 8 9 10
| at Function.use (I:\Develop\blog2\node_modules\express\lib\router\index.js:458:13) at Function. (I:\Develop\blog2\node_modules\express\lib\application.js:220:21)
at Array.forEach ()
at Function.use (I:\Develop\blog2\node_modules\express\lib\application.js:217:7)
at Object. (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
**
源代码如下
**
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| 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(" welcome");
/*
*/
res.render("index");
})
app.listen(8081); |