If a template engine does not expose this
method, you're not out of luck, the app.engine() method allows you to
map any function to an extension. Suppose you had a markdown library
and wanted to render .md files, but this library did not support
Express, your app.engine() call may look something like this:
var markdown = require('some-markdown-library');
var fs = require('fs');
app.engine('md', function(path, options, fn){
fs.readFile(path, 'utf8', function(err, str){
if (err) return fn(err);
str = markdown.parse(str).toString();
fn(null, str);
});
});
If you're looking for a templating engine that lets you use 'plain' HTML, I recommend doT because it is extremely fast.
Of course, keep in mind that the Express 3 view model leaves view caching up to you (or your templating engine). In a production environment, you probably want to cache your views in memory so that you aren't doing disk I/O on every request.
Automatically defaults the Content-Type response header field based on
the filename's extension. The callback fn(err) is invoked when the
transfer is complete or when an error occurs.
Warning
res.sendFile provides client-side cache through http cache headers but it does not cache file contents on server-side. The code above will hit the disk on each request.
In my opinion, using something as big as ejs just to read html files is a bit heavy-handed. I just wrote my own template engine for html files that's remarkably simple. The file looks like this:
add your view templates as .html inside “views” folder. Restart you node server and start the app in the browser.
Though this will render html without any issue, I would recommend you to use JADE by learning it. Jade is an amazing template engine and learning this will help you achieve better design & scalability.