我只是试图将我的快递应用程序与模板/视图引擎,当它涉及到“hbs”它的工作正常,但当我试图使用ejs模板引擎渲染它不工作,因为我预期,我找不到任何问题的代码...需要一些帮助
这是我写的代码:
const path = require("path");
const express = require("express");
const app = express();
const helmet = require("helmet");
app.use(helmet());
app.use(express.static("public"));
app.use(express.json());
app.use(express.urlencoded());
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.get("/", (req, res, next) => {
// res.send("Sanity Check");
// res.json({ msg: "sucess" });
res.render("index");
});
app.listen(3000);
我遇到的错误是这样的:
Error: Cannot find module 'ejs'
Require stack:
- C:\Users\A\node_modules\express\lib\view.js
- C:\Users\A\node_modules\express\lib\application.js
- C:\Users\A\node_modules\express\lib\express.js
- C:\Users\A\node_modules\express\index.js
- C:\Users\A\Desktop\Express\Just Express\express201\rendering.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at new View (C:\Users\A\node_modules\express\lib\view.js:81:14)
at Function.render (C:\Users\A\node_modules\express\lib\application.js:587:12)
at ServerResponse.render (C:\Users\A\node_modules\express\lib\response.js:1039:7)
at C:\Users\A\Desktop\Express\Just Express\express201\rendering.js:21:7
at Layer.handle [as handle_request] (C:\Users\A\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\A\node_modules\express\lib\router\route.js:144:13)
1条答案
按热度按时间2uluyalo1#
以前安装过ejs库吗你?
尝试安装,
npm install ejs