Setting up default view path in Express.js Setting up default view path in Express.js express express

Setting up default view path in Express.js


Try using

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

Your app.js is in your app folder so I think

var viewPath = path.join(__dirname, 'app/views');app.set('views', viewPath);

will look into app/app/views/ instead of app/views/ because of __dirname
__dirname is the directory in which the currently executing script resides.


I actually have separated files in my project, so I have app.get('/', ...) in the separated route file, then require it to use with app.use()

I really have no ideas but after moving only the app.get('/', ...) to the app.js, the problem has been solved

Thanks everyone


As mentioned by Roxinagi, you should be using app.get().Everything else seems fine

app.get('/', function(req, res) {   res.render('index', { title: 'Home Page' } );});