I've an issue in NodeJS, i'm new to this. I'm using nodeJS, express and JQTPL to follow a tutorial about calling the github API but the problem is on the Application configuration, particularly on engine definition.
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");
})
the app.engine call fail, here is the error :
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)
I understand what's a callback.. etc.. but the only way to call app.engine i found is builded like this.
Thank you for your help !
jqtpl seems to be broken (at least the version in the NPM repo; the GH version might work better): it tries to determine the version of Express, but it uses a property (express.version) that doesn't exist anymore.
Here's a workaround:
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);