ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

Error: Failed to lookup view "login" in views directory "/home/access/code/javascript/bv/bv-admin-4.0/app/views #277

Closed bitshiftnetau closed 4 years ago

bitshiftnetau commented 4 years ago

Very basic test usage:


/*
 * Main entry point for the server
 */

global.__basedir = __dirname;

const express = require('express')
var exphbs = require( 'express-handlebars');

const app = express()
const port = (process.env.PORT || 3000);

app.engine( 'hbs', exphbs( {
  extension: 'handlebars',
  defaultView: 'default',
  layoutsDir: __basedir + '/views/pages/',
  partialsDir: __basedir + '/views/partials/'
}));

// view engine setup
app.set('view engine', 'hbs');
app.set('views', __basedir + '/views');

app.get('/', function (req, res) {
  res.render('login');
});

app.listen(port, () => console.log(`Nodemin listening on port ${port}!`))

Here is my folder structure:

|-- server.js
|-- utils
|-- views
|   |-- layouts
|   |   `-- index.handlebars
|   |-- login.handlebars
|   |-- pages
|   |   `-- sections
|   `-- partials
|       `-- google

Error output:

Error: Failed to lookup view "login" in views directory "/home/access/code/javascript/bv/bv-admin-4.0/app/views" at Function.render (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/application.js:580:17) at ServerResponse.render (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/response.js:1012:7) at /home/access/code/javascript/bv/bv-admin-4.0/app/server.js:31:7 at Layer.handle [as handle_request] (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/router/layer.js:95:5) at next (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/router/layer.js:95:5) at /home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/router/index.js:335:12) at next (/home/access/code/javascript/bv/bv-admin-4.0/node_modules/express/lib/router/index.js:275:10)

bitshiftnetau commented 4 years ago

please disregard