Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

ejs - my localhost page shows error No default engine

I was trying to run my app throw nodemon locally but the page keep loading and shows nothing

the list.ejs file

const express = require("express");
const bodyparser = require("body-parser");
const app = express();
app.set('view engine','ejs');
var day = "";
app.get("/",function(req,res){
   var today = new Date();
   if(today.getDay()===5 || today.getDay()===6){
       day = "weekend";
   } else {
       day = "weekday";
   }
    app.render("list",{kindofday:day});
})

app.listen(5000,function(){
    console.log("server is running on 5000");
})

error message :

Error: No default engine was specified and no extension was provided.
    at new View (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslibview.js:61:11)
    at Function.render (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslibapplication.js:570:12)
    at C:UsersfaisaWeb Developmentoollist-v1app.js:13:9
    at Layer.handle [as handle_request] (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslib
outerlayer.js:95:5)
    at next (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslib
outer
oute.js:137:13)
    at Route.dispatch (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslib
outer
oute.js:112:3)
    at Layer.handle [as handle_request] (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslib
outerlayer.js:95:5)
    at C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslib
outerindex.js:281:22
    at Function.process_params (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslib
outerindex.js:335:12)
    at next (C:UsersfaisaWeb Developmentoollist-v1
ode_modulesexpresslib
outerindex.js:275:10)
question from:https://stackoverflow.com/questions/65870340/my-localhost-page-shows-error-no-default-engine

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you need to set the view directory app.set("views", path.join(__dirname, "views")); replace views with the name of your directory


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...