Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to lookup view "index" in views directory

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?

like image 320
user2281858 Avatar asked Apr 13 '16 20:04

user2281858


3 Answers

Try with

app.set('views', __dirname + '/views');
like image 113
Oscar Avatar answered Nov 20 '22 14:11

Oscar


This is how I fixed it.

app.set('views', './src/views');
app.set('view engine', 'ejs');
like image 29
user2281858 Avatar answered Nov 20 '22 14:11

user2281858


I had the same problem too. I have saved the index file as .html file. But it should be index.ejs. then it worked. Check that too

like image 2
maneesha Avatar answered Nov 20 '22 14:11

maneesha