res.render 不是函数?
res.render is not a function?
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const homeStartingContent = "L.";
const aboutContent = "Hac.";
const contactContent = "S.";
const app = express();
const PORT = 3000;
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.get("/", (res, req) => {
res.render("home");
});
app.listen(PORT, function () {
console.log("working");
})
要么是我遗漏了非常简单的东西,要么是我下载的文件已过期。我考虑了第二个选项,所以我重新安装了依赖项。仍然没有工作。我不断收到错误消息“'res.render' 不是一个函数。我梳理了这段代码。我真的不知道我在哪里搞砸了。我什至搞砸了,复制并粘贴了它的变体适用于不同项目的版本。
您传递的参数顺序不正确,
在这里,您将响应作为第一个参数传递,
app.get("/", (res, req) => {
res.render("home");
});
虽然 request 是 expressJS 的任何路由方法的第一个参数,但更新如下,
app.get("/", (req, res) => {
res.render("home");
});
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const homeStartingContent = "L.";
const aboutContent = "Hac.";
const contactContent = "S.";
const app = express();
const PORT = 3000;
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.get("/", (res, req) => {
res.render("home");
});
app.listen(PORT, function () {
console.log("working");
})
要么是我遗漏了非常简单的东西,要么是我下载的文件已过期。我考虑了第二个选项,所以我重新安装了依赖项。仍然没有工作。我不断收到错误消息“'res.render' 不是一个函数。我梳理了这段代码。我真的不知道我在哪里搞砸了。我什至搞砸了,复制并粘贴了它的变体适用于不同项目的版本。
您传递的参数顺序不正确, 在这里,您将响应作为第一个参数传递,
app.get("/", (res, req) => {
res.render("home");
});
虽然 request 是 expressJS 的任何路由方法的第一个参数,但更新如下,
app.get("/", (req, res) => {
res.render("home");
});