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?
Try with
app.set('views', __dirname + '/views');
This is how I fixed it.
app.set('views', './src/views');
app.set('view engine', 'ejs');
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With