Last active
August 29, 2015 14:21
-
-
Save sgimeno/e3dab2c9121336de57c8 to your computer and use it in GitHub Desktop.
Compile EJS in an ExpressJS route handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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