Why is express telling me that my default view engine is not defined?
The source of the error describes the requirements:
if (!ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.');
Express expects that you either specify the view with its extension:
res.render('index.html');
Or specify a default view engine and name your views after it:
app.set('view engine', 'ejs');// `res.render('index')` renders `index.ejs`
Regarding your edit:
if ('function' != typeof fn) throw new Error('callback function required');
The issue is with this line:
app.engine('.html', require('ejs').renderFile());
As the documentation demonstrates, app.engine()
is expecting a function
reference. You can do this by simply removing the ()
that call renderFile
:
app.engine('.html', require('ejs').renderFile);
need to do all the app.set
and app.use
in an app.configure
try this
app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('view engine', 'ejs'); app.engine('.html', require('ejs').renderFile()); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); // development only if ('development' == app.get('env')) { app.use(express.errorHandler()); }});