我不明白我的代碼哪里出錯了。請幫我。每當我運行此代碼(終端中的 nodemon app.js)時,我都會在瀏覽器中收到錯誤(錯誤:-無法獲取)。預先感謝您幫助我。
app.js code:-
const express =require("express")
const bodyParser=require("body-parser");
const app=express();
app.set("view engine","ejs");
app.set("/",function (req,res) {
var today=new Date();
var day="";
if(today.getDay()==6||today.getDay()==0)
day="weekend";
else
day="weekday";
res.render("todo", { kindofDay: day});
});
app.listen(3000,function() {
console.log('server is starting...');
});
todo.ejs code:-
<!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>Ejs day list</title>
</head>
<body>
<h1>It's a <%= kindofDay %> !</h1>
</body>
</html>
uj5u.com熱心網友回復:
你必須使用 app.get
app.get("/",function (req,res) {
var today=new Date();
var day="";
if(today.getDay()==6||today.getDay()==0)
day="weekend";
else
day="weekday";
res.render("todo", { kindofDay: day});
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/324655.html
上一篇:錯誤:找不到模塊'webpack/lib/rules/DescriptionDataMatcherRulePlugin'需要堆疊:
