Set the lookup path of view folder of ejs in express

99封情书 提交于 2020-01-04 04:01:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!