Skip to content

Instantly share code, notes, and snippets.

@sgimeno
Last active August 29, 2015 14:21
Show Gist options
  • Save sgimeno/e3dab2c9121336de57c8 to your computer and use it in GitHub Desktop.
Save sgimeno/e3dab2c9121336de57c8 to your computer and use it in GitHub Desktop.
Compile EJS in an ExpressJS route handler
function (req, res){
var ejs = require('ejs');
var fs = require('fs');
var async = require('async');
async.map([__dirname + '/template.ejs'], fs.readFile, function(err, files) {
if(err) {
throw err;
}
//Set the content type depending on what kind of file we are returning
res.setHeader('Content-Type', 'application/javascript');
var template = ejs.compile(files[0].toString());
return res.send(template({some: 'data'}));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment