I just stumbled upon this ancient thread, but no one mentioned the .js union, which seems to be the βrightβ way in Express Express (see http://expressjs.com/faq.html ). It also provides an easy way to switch / experiment with template systems.
Here is a simple example - http://invitingthebell.com/2012/12/24/mustache-templates-in-express-3-0/ .
Code, in case of its disappearance:
var express = require('express') , cons = require('consolidate') , app = express(); // assign the mustache engine to .html files app.engine('html', cons.mustache); // set .html as the default extension app.set('view engine', 'html'); app.set('views', __dirname + '/views'); // test mustache app.get('/', function(req, res){ var viewdata = { 'test' : 'Hey now.'}; res.render('index', viewdata); }); app.listen(3000);
The index.html file in the views directory:
<html> <head><title>Some CMS</title></head> <body> <h1>Mustache</h1> <p>What do you say?</p> <p>{{test}}</p> </body> </html>
source share