Saya juga menghadapi masalah yang sama di express 3.Xdan node 0.6.16. Solusi yang diberikan di atas tidak akan berfungsi untuk versi terbaru express 3.x. Mereka menghapus app.registermetode dan menambahkan app.enginemetode. Jika Anda mencoba solusi di atas, Anda mungkin berakhir dengan kesalahan berikut.
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)
Untuk menghilangkan pesan kesalahan. Tambahkan baris berikut keapp.configure function
app.engine('html', require('ejs').renderFile);
Catatan: Anda harus menginstal ejsmesin template
npm install -g ejs
Contoh:
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");
});
Catatan: Solusi paling sederhana adalah dengan menggunakan template ejs sebagai view engine. Di sana Anda dapat menulis HTML mentah di file tampilan * .ejs.