24 1 / 2012
Node.js and ejs
So I been working with node.js for about 3 months or so now on a new project and I started out use swig.js as my templating language.
Swigs syntax will be very familiar to you all if your used to using twig for php and especially python Django’s templating language where pretty much everyone got their ideas from.
{% extends "base_generic.html" %}{% block title %}{{ section.title }}{% endblock %} {% block content %}
You can do cool things with this style templating language, especially my favorite, filters
{{ story.headline|upper }}
The above will turn the dynamic value of that variable to all uppercase case letters. Cool eh? The only problem is that swig doesnt really come out the box for expressjs. I got it to work but it doesnt really play too nice, especially when it comes to development. Testing code is not so great when having to restart the application everytime when making html edits.
So Ive turned my energy to EJS. Which if you looked at my packages blog you can just require(‘ejs’) in your dependacies and add
app.set(‘view engine’, ‘ejs’);
to your app.configure(); function for expressjs. Now your all set and ready to use it right out of the box for expressjs. If you want to start playing around with ejs and see how cool it is, visit thier website and checkout the live editor at
It doesnt have all the cool features of the polished Django framework, but with cool features like the json live update, it really fit perfectly for my node.js app. It also is sooo micro compared to a lo templating t of other engines out there. Hope you guys check it out and let me know what you all think.