热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Router.use()requiresamiddlewarefunction错误提示

错误提示如下:D:ProgramFilesJetBrainsWebStorm2017.2.4binrunnerw.exeD:Program

错误提示如下:
"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);




   



推荐阅读
author-avatar
lululove8_530
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有