GevAlter GevAlter - 1 year ago 94
Javascript Question

nodejs handlebars error TypeError: this.set is not a function

hey smart people that want to help me!

im a nodejs beginner and i want to use handlebars as my template engine...
this is my first nodejs application, i follow this guide:

i use cloud9 as my ide..

i have only one js file its realy everything:

var express = require('express');
var app = express();
var hbs = require('express3-handlebars');

app.engine = ('handlebars', hbs({defaultLayout: 'layout'}));
app.set = ('view engine', 'handlebars');

app.get('/', function (req,res){


app.listen(process.env.PORT || 3000, process.env.IP || "");

im doing everything that the guide refernce me to do...
this is my folder tree:

update: this is the error that i get.. forgot to put it here:

return Boolean(this.set(setting));

TypeError: this.set is not a function
at EventEmitter.enabled (/home/ubuntu/workspace/node_modules/express/lib/application.js:421:23)
at EventEmitter.lazyrouter (/home/ubuntu/workspace/node_modules/express/lib/application.js:139:27)
at function) [as get] (/home/ubuntu/workspace/node_modules/express/lib/application.js:478:10)
at Object. (/home/ubuntu/workspace/server.js:8:5)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.runMain [as _onTimeout] (module.js:441:10)
at Timer.listOnTimeout (timers.js:92:15)

Answer Source

Fix these lines :

app.engine('handlebars', hbs({defaultLayout: 'layout'}));
app.set('view engine', 'handlebars');

And for another, change layout.hbs to layout.handlerbars