Answers for "error: failed to lookup view "layout" in views directory"

1

error: failed to lookup view "layout" in views directory

Make sure your Express App has this setup, for the current layout it sounds like you have.

// Require static assets from public folder
app.use(express.static(path.join(__dirname, 'public')));

// Set 'views' directory for any views 
// being rendered res.render()
app.set('views', path.join(__dirname, 'views'));

// Set view engine as EJS
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
It is pretty normal for views that are getting rendered by res.render() to be placed in a 'Views' directory at the top level of your app. The express-generator actually uses that view setup. You can change that by modifying the below line

// replace with the directory path below ./
app.set('views', path.join(__dirname, 'views'));
Posted by: Guest on March-16-2021

Code answers related to "error: failed to lookup view "layout" in views directory"

Browse Popular Code Answers by Language