Node.js nodeJS+;express+;jqtpl+;app.engine

Node.js nodeJS+;express+;jqtpl+;app.engine,node.js,express,Node.js,Express,我在NodeJS有个问题,我是新手。 我使用nodeJS、express和JQTPL来学习关于调用githubapi的教程,但问题在于应用程序配置,特别是引擎定义 var express = require('express'), app = express(), ... ; app.configure(function(){ app.set('view engine', 'html'); app.set('view options', {lay

我在NodeJS有个问题,我是新手。 我使用nodeJS、express和JQTPL来学习关于调用githubapi的教程,但问题在于应用程序配置,特别是引擎定义

    var express = require('express'),
    app = express(),
    ...
    ;

app.configure(function(){
    app.set('view engine', 'html');
    app.set('view options', {layout: false});
    app.engine('.html', require('jqtpl').__express);
    });

// When we go to the URL "/" we go the the index.html
app.get("/", function(req, res){
    res.render("index");
});

app.get("/board", function(req, res) {
    res.render("board");
})
app.engine调用失败,错误如下:

 if ('function' != typeof fn) throw new Error('callback function required');

    ^
Error: callback function required
    at Function.app.engine (/var/lib/stickshift/51d5872b5973ca8338000033/app-root/data/547742/node_modules/express/lib/application.js:173:38)
    at Function. (/var/lib/stickshift/51d5872b5973ca8338000033/app-root/data/547742/app.js:15:9)
    at Function.app.configure (/var/lib/stickshift/51d5872b5973ca8338000033/app-root/data/547742/node_modules/express/lib/application.js:392:61)
    at Object. (/var/lib/stickshift/51d5872b5973ca8338000033/app-root/data/547742/app.js:12:5)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
我知道什么是回拨。。等但我找到的调用app.engine的唯一方法是这样构建的


谢谢你的帮助

jqtpl
似乎已损坏(至少是NPM repo中的版本;GH版本可能更好):它试图确定Express的版本,但它使用的属性(
Express.version
)已不存在

以下是一个解决方法:

var express = require('express');
var app     = express();

app.configure(function(){
  app.set('view engine', 'html');
  app.engine('html', require('jqtpl/lib/express').render);
});

app.get("/", function(req, res){
  res.render("index"); // this renders "views/index.html"
});

app.listen(3013);

好的,谢谢你,我在等你回答的时候用了玉。我要试试这个。您编写了res.render(index)render public/index.html,但我认为express在视图/中查找页面。我错了吗?事实上,现在我的应用程序没有重定向到index.html,我还没有搜索解决方案,但可能是因为我把index.html放在了views/?再次感谢你,你给了我另一个希望,并让它回来!无论如何谢谢你@ogdabou您想从
/index.html
重定向到
/
?不,我想从/to/index重定向。html@ogdabou那会很容易(
app.get('/,function(req,res){res.redirect('/index.html')})
),但你为什么想要这样呢?