1

I get the following error No default engine was specified and no extension was provided on trying to render template like the following:

app.get('/', function (req, res, next) {
    return res.render('index');
});

In my server.js config I've added the following lines:

app.engine('jade', require('jade').__express);
app.set('views', __dirname + '/views');

What's my problem?

EDIT: and what is app.engine('jade', require('jade').__express); mean and what cases should I use it?

Erik
  • 14,060
  • 49
  • 132
  • 218
  • Your two snippets look OK to me but something must be going wrong in the code you omitted. Can you post a complete, minimal file to reproduce this? If you want a quick fix just do `res.render('index.jade')`, but that won't be necessary once the root cause is fixed properly. I also suspect your views path is not what you think it is. – Peter Lyons Jul 26 '14 at 14:16
  • unfortunately I can't post a complete, minimal file to reproduce this. I use express4 and it get works if I use `app.set('view engine', 'jade');` but I don't understand what is `app.engine('jade', require('jade').__express);` mean? – Erik Jul 26 '14 at 14:21
  • possible duplicate of [Why is express telling me that my default view engine is not defined?](http://stackoverflow.com/questions/17560760/why-is-express-telling-me-that-my-default-view-engine-is-not-defined) – Rahil Wazir Jul 26 '14 at 15:06
  • @Erik It only tells express what extension your view engine uses. However, as Jade is a recognized engine, you don't need it. `app.set('view engine', 'jade')` is enough for Express to know that `app.render('index')` means `app.render('index.jade')`. If you were using an unusual view engine, that line might be necessary to indicate Express what file extension should be used when looking for views. – Waldo Jeffers Jul 26 '14 at 15:59

0 Answers0