如何配置express.js / jade来处理html文件?

时间:2012-08-20 23:05:26

标签: node.js express pug

我想配置jade引擎来处理我的views文件夹中的.html文件。这是我的currentserver配置:

app.configure(function(){
  var pub_dir = __dirname + '/public';
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser());
  app.use(express.session({ secret: nconf.get("site:secret") }));
  app.use(everyauth.middleware());  
  app.use(require('less-middleware')({ src: pub_dir, force:true }));
  app.use(express.static(pub_dir)); 
  app.use(app.router);
  app.use(logErrors);
  app.use(clientErrorHandler);
  app.use(errorHandler);
});

2 个答案:

答案 0 :(得分:6)

https://github.com/visionmedia/express/blob/master/examples/ejs/index.js

app.engine('.html', require('jade').__express);

答案 1 :(得分:1)

确保jade

中已有node_modules
npm install --save jade

在express 4.x中,您只需将view engine设置为jade

app.set('view engine', 'jade')