我刚刚开始学习Node.js。我当前正在使用Node Express创建Web应用程序。当我尝试将route.js文件合并到我的app.js中时。终端出现错误:
引发新的TypeError :('app.use()需要中间件功能')
该问题仅存在于app.use()语句中,因为我已尝试通过注释该语句来启动该应用程序,但效果很好。但是,如果包含该语句,则会显示错误。
routes.js
var express = require("express");
var router = express.Router();
router.get("/", function(req, res) {
console.log("Welcome ! You are at the start page of your web
application");
});
module.exports = router;
app.js
var express = require("express");
var path = require("path");
var routes = require("./routes");
var app = express();
app.set("port", process.env.PORT || 3000);
app.use(routes);
app.listen(app.get("port"),function(){
console.log("Server started on port " + app.get("port"));
});