Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

492
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda