Example Node.js Express Registration of Underscore.js as a Viewer?

Underscore.js does not have a compilation function like ejs and jade, but it works like a Node.js module. Someone please give an example of how to make it work in an Express application?

+8
javascript express
source share
2 answers
var _ = require('underscore'); app.register('.html', { compile: function (str, options) { var template = _.template(str); return function (locals) { return template(locals); }; } }); 
+20
source share

Now with express 3.0 this is a little different. Simple solution: https://github.com/haraldrudell/uinexpress

 npm install uinexpress 

then

 app.configure(function () { app.engine('html', require('uinexpress').__express) app.set('view engine', 'html') 
+4
source share

All Articles