问题
I have app.js in Express_server folder.Full location of aap.js is I:\WEB Development\Node\Express_server\
and I made views folder at the location I:\WEB Development\Node\
How can I set the lookup path of views folder to above location(I:\WEB Development\Node)?
code of my app.js
const express = require('express');
const app = express();
app.set('view engine', 'ejs');
app.get('/',function(req, res){
res.render('index');
});
回答1:
You can change your views default path:
app.set('views', path.join(__dirname, '../views'))
回答2:
const express = require('express')
const app = express()
const port = 3000
require("./route/route.js")(app);
app.set('views', path.join(__dirname, '../views'))
app.set('view engine','ejs');
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
来源:https://stackoverflow.com/questions/45903473/set-the-lookup-path-of-view-folder-of-ejs-in-express