How to resolve the issue associate with EJS?

Viewed 27

I am getting error in nodejs app . i am using ejs template for rendering pages. EJS template engine showing error.

app.set('view engine', 'ejs');
//app.set('view engine', 'pug') 
var path = require('path');
app.set('views', path.join(__dirname, 'views'));  
app.use(express.static(__dirname +'/public'));  

Above is my code for views engine but i am getting error like below

Error: Failed to lookup view "error" in views directory "/home/simawedl/mynode/views"

How do solve my issue? My folder structure is root/views/

I tried few solutions mentioned in stackoverflow but not solved. I think issue with ejs view engine but showing error. i tried many solutions in stackoverflow but no use.

1 Answers

The error message means that your express app could not find a file error.ejs in the folder "/home/simawedl/mynode/views". Once you create that file, this error will be gone.

Here is a simple example of such file that will print the error details:

<!DOCTYPE HTML>
<html>
  <head>
    <title>Error</title>
  </head>
  <body>
    <h1><%= message %></h1>
    <h2><%= error.status %></h2>
    <pre><%= error.stack %></pre>
  </body>
</html>
Related