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'));

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Failed to lookup view "../views/index" in views directory Error: Failed to lookup view in views directory " Failed to lookup view "/" in views directory Error: Failed to lookup view "index" in views directory "./views" Error: Failed to lookup view "/posts/new" in views directory Error: Failed to lookup view in views directory Error: Failed to lookup view "about" in views directory "views" Failed to lookup view "layout" in views directory "/mnt/c Failed to lookup view "layouts/layout" in views directory Failed to lookup layout in views directory nide Error: Failed to lookup view "../main" in views directory Failed to lookup view "views/index" in views directory Error: Failed to lookup view "errors/error" in views directory Error: Failed to lookup view "/" in views directory Failed to lookup view in views directory Error: Failed to lookup view "/index" in views directory Error: Failed to lookup view "home" in views directory "views" Error: Failed to lookup view "about" in views directory Failed to lookup view "./views" in views directory Error: Failed to lookup view "views/home" in views directory Error: Failed to lookup view "room" in views directory Failed to lookup view in views directory Failed to lookup view /views/dashboard in views directory Error: Failed to lookup view "index" in views directory render Error: Failed to lookup view "./index" in views directory Error: Failed to lookup view "/" in views directory "views" Error: Failed to lookup view "error" in views directory Error: Failed to lookup view "./home" in views directory Error: Failed to lookup view in views directory Error: Failed to lookup view "dashboard" in views directory Error: Failed to lookup view "main" in views directory Failed to lookup view "error" in views directory Error: Failed to lookup view "index" in views directory Error: Failed to lookup view "index" in views directory "views" Failed to lookup view "layout" in views directory error: failed to lookup view "layout" in views directory
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source