Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

491
Views
Error in trying to open web page with nodejs express

I am trying to develop a web page with nodejs express and mongodb. I have followed and analyzed the code from this GitHub page and I'm getting an error while trying to open the web page.

When uncommenting the below code part in app.js and commenting the rest portion of the code in the app.js file (uncommented code part):

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var hbs = require('express-handlebars');

var routes = require('./routes/index');

var app = express();

// view engine setup
app.engine('hbs', hbs({extname: 'hbs', defaultLayout: 'layout', layoutsDir: __dirname + '/views/layouts/'}));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

The following output is obtained:

Cannot GET /

When uncommenting all the statements in the app.js and executing to open the web page, the following output is obtained:

Error: Failed to lookup view "error" in views directory "C:\Users\web\first-1\views"
    at EventEmitter.render (C:\Users\web\first-1\node_modules\express\lib\application.js:580:17)
    at ServerResponse.render (C:\Users\web\first-1\node_modules\express\lib\response.js:966:7)
    at C:\Users\web\first-1\app.js:53:7
    at Layer.handle_error (C:\Users\web\first-1\node_modules\express\lib\router\layer.js:71:5)
    at trim_prefix (C:\Users\web\first-1\node_modules\express\lib\router\index.js:315:13)
    at C:\Users\web\first-1\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\web\first-1\node_modules\express\lib\router\index.js:335:12)
    at IncomingMessage.next (C:\Users\web\first-1\node_modules\express\lib\router\index.js:275:10)
    at done (C:\Users\web\first-1\node_modules\express\lib\response.js:961:25)
    at EventEmitter.render (C:\Users\web\first-1\node_modules\express\lib\application.js:582:14)

Kindly help me out of this.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

app.set('views', path.join(__dirname, 'views'));

You have specified views directory for your app views. res.render looks for the files in the views directory, not in the sub directories of views. Copy your error.hbs from views/layouts to views/ and try.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!