[英]app.set('view engine','ejs'); ^ TypeError: app.set is not a function
Problem in the template engine in express
validation express
验证中模板引擎的问题
I m expecting to resolve my problem我期待解决我的问题
app.js应用程序.js
const express=require('express')
const app= express;
const port = 5000;
//set template engine
app.set('view engine','ejs')
//navigation
app.get('',(req,res)=>{
res.render('index')
})
app.get('/resgiter',(req,res)=>{
res.render('resgiter')
})
app.listen(port,() =>
console.info(`App listening on port:${port}`)
)
error in the template engine模板引擎错误
You missed to invoke express
in second line of Your code:您错过了在代码的第二行调用
express
:
Instead of:代替:
const app = express;
You should provide:你应该提供:
const app = express();
and forward slash /
in this snippet:和正斜杠
/
在此代码段中:
app.get("/", (req, res) => {
res.render("index");
});
app.js应用程序.js
const express = require("express");
const app = express();
const port = 5000;
//set template engine
app.set("view engine", "ejs");
//navigation
app.get("/", (req, res) => {
res.render("index");
});
app.get("/resgiter", (req, res) => {
res.render("resgiter");
});
app.listen(port, () => console.info(`App listening on port:${port}`));
index.ejs索引.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>ejs it's Awesome! ;-)</h1>
</body>
</html>
folder&file structure and console output :文件夹和文件结构和控制台 output :
browser output :浏览器 output :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.