javascriptnode.jsexpressejs

Set the lookup path of view folder of ejs in express


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');
});

Solution

  • You can change your views default path:

    app.set('views', path.join(__dirname, '../views'))