title: Error: Failed to lookup view "error" in views directory using handlebars
body: <p>Hi I am very new to web development in Node JS. At work today I was tasked to setup an environment for a web application. I am using handlebars, but I am having trouble making 'view engine setup' to work in order to render the 'views' files and the layouts folder. I have looked at the documentation and every stack overflow post that is similar to my issue, but I still get nowhere. Here is my code below for server.js and the architecture of my app. I will really appreciate any feedback thanks in advance!</p>
  
  <pre><code> var express = require('express');
      var path = require('path');
      var handlebars = require('handlebars');
      var exphbs = require('express-handlebars');
      var app = express();
      var cookieParser = require('cookie-parser');
      var bodyParser = require('body-parser');
  
      //view engine setup
      app.set('views', './views')
      app.engine('.hbs', exphbs({ defaultLayout: 'main', extname: '.hbs' }));
      app.set('view engine', '.hbs');
  
      app.use(bodyParser.json());
      app.use(bodyParser.urlencoded({ extended: false }));
      app.use(cookieParser());
      app.use(express.static(__dirname + '/public'));
  
      //routes
      app.get('/home', function(req, res){
      res.render('home');
      });
      //error handlers
      //404 catch-all handler(middleware)
      app.use(function(req, res, next){
      res.status(404);
      res.send('404');
     });
      //500 error handler(middleware)
      app.use(function(req, res, err, next){
        console.error(err.stack);
        res.status(500);
        res.send('500');
     });
     // development error handler
     // will print stacktrace
     if (app.get('env') === 'development') {
       app.use(function(err, req, res, next) {
         res.status(err.status || 500);
         res.render('error', {
           message: err.message,
           error: err
         });
       });
     }
     // production error handler
     // no stacktraces leaked to user
     app.use(function(err, req, res, next) {
       res.status(err.status || 500);
       res.render('error', {
         message: err.message,
         error: {}
       });
     });
  
  app.listen(process.env.PORT || 5000);
  console.log('Listening on port 5000');
  
  
  fgcms
  ├── server.js
  ├── node_modules
  └── package.json
  ├── public
  └── views
         ├── layouts──home.hbs
         └──main.hbs
  </code></pre>