Ben de aynı sorunla karşı karşıya express 3.Xve node 0.6.16. Yukarıda verilen çözüm en son sürüm için çalışmaz express 3.x. app.registerYöntemi kaldırdılar ve yöntem eklediler app.engine. Yukarıdaki çözümü denediyseniz, aşağıdaki hatayla karşılaşabilirsiniz.
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'register'
at Function.<anonymous> (/home/user1/ArunKumar/firstExpress/app.js:37:5)
at Function.configure (/home/user1/ArunKumar/firstExpress/node_modules/express/lib/application.js:399:61)
at Object.<anonymous> (/home/user1/ArunKumar/firstExpress/app.js:22:5)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
Hata mesajından kurtulmak için. Aşağıdaki satırıapp.configure function
app.engine('html', require('ejs').renderFile);
Not: ejsşablon motorunu kurmanız gerekir
npm install -g ejs
Misal:
app.configure(function(){
.....
// disable layout
app.set("view options", {layout: false});
app.engine('html', require('ejs').renderFile);
....
app.get('/', function(req, res){
res.render("index.html");
});
Not: En basit çözüm ejs şablonunu görüntüleme motoru olarak kullanmaktır. Orada * .ejs görünüm dosyalarına ham HTML yazabilirsiniz.