Change the default view directory in ExpressJs

When we use ExpressJs for a NodeJs application we need to place our views in a folder named "views". That is the default settings of ExpressJs.

But sometimes we might want to change that location if we use a different structure. So I thought it would be a good idea to write about that configuration though it is a small thing.

This is how we import the express module and create a instance of express.

var express = require('express');
var app = express();

express.set() method can be used to set the path for views folder as follows. "partials" is the name of new views directory.

app.set('views',__dirname+'/partials');

__dirname gives the absolute path of the current directory.

No comments:

Post a Comment