Is it possible to create an express (node) application without the need for a template engine such as jade or ejs. I\'ve got a large final year project at university and i\'
If you only want to avoid learning another template language, you might want to give underscore templates a try. They're just javascript, which you're going to be learning anyway.
documentcloud.github.com/underscore/#template
You can set it up with:
app.register('.html', {
compile: function(str, options){
var compiled = require('underscore').template(str);
return function(locals) {
return compiled(locals);
};
}
});
Is it possible to create an express (node) application without the need for a template engine such as jade or ejs
Yes it is. You can just use HTML. Or just use EJS. EJS is a superset of HTML.
I don't want to burden myself with having to learn a templating language too!
You can learn a templating language in a day. It's really going to help you. Just do it. It's worth it.
The best option right now is to use ejs (engine) and configure it to accept and render html:
app.set('views', path.join(*__dirname*, 'views'))
app.set('view engine', 'ejs'); // template engine
app.engine('html', require('ejs').renderFile); // turn engine to use html
Note: All your views or templates have the .html
extension.
Easiest way to do this would be to replace the default app.get('/')... line with the following. Then put all the magic in index.html. This will at least work quite well for a single page app.
with the following
app.get('/', function(request, response) {
var readFile = "index.html";
var fileContents = fs.readFileSync(readFile);
response.send(fileContents.toString());
});