0
votes

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: https://www.youtube.com/watch?v=m5ribwPpIPw

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){
  res.render('index');
});

app.use('/views',express.static('views'));

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

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:

/home/ubuntu/workspace/node_modules/express/lib/application.js:421 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 EventEmitter.methods.forEach.app.(anonymous 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)

2

2 Answers

2
votes

Fix these lines :

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

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

0
votes

FYI - 'express3-handlebars' has been changed to just 'express-handlebars'. You may want to update that. See here.

Also, if you want to name your layouts with a .hbs extension, you can.

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