2016-02-09 106 views
0

我正在通過網頁開發與節點&表達:利用JavaScript堆棧,由Ethan布朗。我在第三章介紹Express的基本概念。我創建的應用程序,meadowlark.js,正如書中所說,並且我得到關於把手模板引擎這個錯誤:把手模板引擎沒有定義

ReferenceError: handlebars is not defined at Object.<anonymous> (/PROJECT_STORAGE/site/meadowlark.js:7:26) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3

這裏是我如何安裝把手,其餘的代碼的meadowlark.js

var express = require('express'); 
 

 
var app = express(); 
 

 
// setup handlebars view engine 
 
var handlbars = require('express-handlebars').create({ defaultLayout: 'main' }); 
 
app.engine('handlebars', handlebars.engine); 
 
app.set('view engine', 'handlebars'); 
 
app.set('views', __dirname + '/views'); 
 

 
app.set('port', process.env.PORT || 3000); 
 

 
app.get('/', function(req, res) { 
 
\t res.render('home'); 
 
}); 
 

 
app.get('/about', function(req, res) { 
 
\t res.type('about'); 
 
}); 
 

 
// custom 404 pg 
 
app.use(function(req, res) { 
 
\t res.status(404); 
 
\t res.render('404'); 
 
}); 
 

 
// custom 500 pg 
 
app.use(function(err, req, res, next) { 
 
\t //console.error(err.stack); 
 
\t res.status(500); 
 
\t res.render('500'); 
 
}); 
 

 
app.listen(app.get('port'), function() { 
 
\t console.log('Express started on localhost:' + app.get('port') + '; press Ctrl-C to terminate.'); 
 
});

ħ我可以修復我的代碼,使Handlebars正確初始化並使handlebars.js運行?

回答

1

錯字var handlbars = require('express-handlebars').create({ defaultLayout: 'main' });

應該var handlebars

專業提示:在你的IDE上使用棉絨。