javascript - Error: Failed to lookup view "error" in views directory using handlebars -


hi new web development in node js. @ work today tasked setup environment web application. using handlebars, having trouble making 'view engine setup' work in order render 'views' files , layouts folder. have looked @ documentation , every stack overflow post similar issue, still nowhere. here code below server.js , architecture of app. appreciate feedback in advance!

 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    // 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 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 


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)