0

我正在尝试启动此 NodeJS 服务器,但收到 TypeError 消息,我已将我的 Express 更新到最新版本。我认为 JST 还不能与 express 3 一起使用,但我找不到是这种情况还是我的代码有问题。我的代码如下:

**Express 500 
TypeError: Property 'engine' of object #<View> is not a function**

at View.render (C:\wip\node_modules\express\lib\view.js:75:8)
at Function.app.render (C:\wip\node_modules\express\lib\application.js:501:10)
at ServerResponse.res.render (C:\wip\node_modules\express\lib\response.js:719:7)
at C:\wip\server.js:40:7
at callbacks (C:\wip\node_modules\express\lib\router\index.js:160:37)
at param (C:\wip\node_modules\express\lib\router\index.js:134:11)
at pass (C:\wip\node_modules\express\lib\router\index.js:141:5)
at Router._dispatch (C:\wip\node_modules\express\lib\router\index.js:169:5)
at Object.router (C:\wip\node_modules\express\lib\router\index.js:32:10)
at next (C:\wip\node_modules\express\node_modules\connect\lib\proto.js:190:15)


var express = require('express'),
jst = require('jst'),
locales = require('locales');

var app = express();

// Configuration
locales.configure({ locales: __dirname + '/locales' });

app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jst');
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(function(req, res, next) { req.lang = 'en'; next(); });
    app.use(locales.detector); // for i18n
    app.use(app.router);
    app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
});

app.configure('production', function(){
    app.use(express.errorHandler()); 
});

// Routes
app.get('/', function(req, res){
    res.render('index', {
    title: 'Express'
    });
});

if (!module.parent) { app.listen(3000); console.log("Express server running"); }
4

1 回答 1

0

I figured out that JST does not support Express 3x. So I'm changing to another templating engine like HBS.

于 2012-12-06T15:27:00.597 回答