Failed to lookup view "index" in views directory

user2281858 picture user2281858 · Apr 13, 2016 · Viewed 8.6k times · Source

I am trying to learn node.js.

I have the following code.

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

var port = process.env.PORT || 5000;

app.use(express.static('public'));
app.use(express.static('src/views'));

app.set('view engine', 'ejs');

app.get('/', function(req, res) {
    res.render('index', { title: 'Hello from render', nav: ['Books', 'Author'] });
});

Failed to lookup view "index" in views directory I have the file named index.ejs. How can I get rid of this error?

Answer

Oscar picture Oscar · Apr 13, 2016

Try with

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