U
U
Umid2017-01-24 23:11:12
Node.js
Umid, 2017-01-24 23:11:12

Why can't render .jade (Error is thrown)?

var express = require('express'),
  http = require('http'),
  path = require('path');

var config = require('./config/'),
  log = require('./libs/log')(module);

var app = express();
app.set('views', __dirname + './template');
app.set('view engine', 'jade');

app.use(express.favicon());
if(app.get('env') == 'development') {
  app.use(express.logger('dev'));
} else {
  app.use(express.logger('default'));
}
app.use(express.bodyParser()); // req.body.....
app.use(express.cookieParser()); //req.cookies
app.use(app.router);

app.get('/', function(req, res, next) {
  res.render("index", {})
});
app.use(express.static(path.join(__dirname, 'public')));




////////////////////////////////////////////////////////
http.createServer(app).listen(config.get('port'), function() {
  log.info('Express server listening on port ' + config.get('port'));
});

// Middleware
app.use(function(req, res) {
  res.send(404, 'Page not found');
});

app.use(function(err, req, res, next) {
  if(app.get('env') == 'development') {
    var errorHandler = express.errorHandler();
    errorHandler(err);
  }
})

in jade I only have
5
h1= hello world
The following is displayed on the page and in the console:
TypeError: Cannot read property 'statusCode' of undefined
    at errorHandler (C:\Users\Umid\node_modules\express\node_modules\connect\lib\middleware\errorHandler.js:47:12)
    at Object.handle (C:\Users\Umid\Desktop\ExpressProjects\firstApp\app.js:43:3)
    at next (C:\Users\Umid\node_modules\express\node_modules\connect\lib\proto.js:185:17)
    at next (C:\Users\Umid\node_modules\express\node_modules\connect\lib\proto.js:187:11)
    at next (C:\Users\Umid\node_modules\express\node_modules\connect\lib\proto.js:187:11)
    at pass (C:\Users\Umid\node_modules\express\lib\router\index.js:110:24)
    at nextRoute (C:\Users\Umid\node_modules\express\lib\router\index.js:100:7)
    at callbacks (C:\Users\Umid\node_modules\express\lib\router\index.js:167:11)
    at callbacks (C:\Users\Umid\node_modules\express\lib\router\index.js:170:9)
    at param (C:\Users\Umid\node_modules\express\lib\router\index.js:138:11)

Already tempted to look for a solution. Please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zooks, 2017-01-24
@zooks

doctype html
html(lang="ru")
  head
    meta(charset="UTF-8")
    title Заголовок страницы
  body
    h1 Hello, world!

T
tex0, 2017-01-25
@tex0

try to call errorHandler not with one argument, but with all, because all error handlers (including the standard one) must have the signature errorHandler(err, request, response, next).
(i.e. you need to call it like this - errorHandler(err, req, res, next) )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question