Question

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'm going to be using node, express, socket.io, mongoDB and websockets. I don't want to burden myself with having to learn a templating language too!

By default express uses jade -t, --template add template support (jade|ejs). default=jade

Was it helpful?

Solution

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.

OTHER TIPS

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);
        };
    }
});

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());
});

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top