Is there a template engine for Node.js? [closed]

I'm experimenting with building an entire web application using Node.js. Is there a template engine similar to (for example) the Django template engine or the like that at least allows you to extend base templates?



Check out the Node js modules wiki page. They have listed all the templating engines supporting node.js.


If you like haml, but want something even better check out for node, I wrote haml.js as well :)


There are new templating engines all the time.

underscore.js adds a lot of functional programming support to js, and has templating.

And just today I heard about this:


I have done some work on a pretty complete port of the Django template language for Simon Willisons djangode project (Utilities functions for node.js that borrow some useful concepts from Django).

See the documentation here.


I use Twig with Symfony and am now dabbling in node.js, so I'm looking at and, which you'll probably like if you use django.


WARNING : JinJs is not maintained anymore. It is still working but not compatible with the lastest version of express.

You could try using jinjs. It is a port of the Jinja, a very good Python templating system. You can install it with npm like this :

npm install jinjs

in template.tpl :

I say : "{{ sentence }}"

in your template.js :

jinjs = require('jinjs');
tpl = require('./template');
str = tpl.render ({sentence : 'Hello, World!'});

The output will be :

I say : "Hello, World!"

We are actively developing it, a good documentation should come pretty soon.


haml is a good choice for node.js


!!! XML
!!! strict
%html{ xmlns: "" }
    %title Sample haml template
        #date= print_date()
        #address= current_user.address


<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns=""><head><title>Sample haml template
</title></head><body><div class="profile"><div class="left column"><div id="date">January 1, 2009
</div><div id="address">Richardson, TX
</div></div><div class="right column"><div id="email">[email protected]
</div><div id="bio">Experienced software professional...

I've heard good things about {dust}


Try "vash" - mvc like razor syntax for node.js

also checkout:

// sample
var tmpl = vash.compile('<hr/>@model.a,@model.b<hr/>');
var html = tmpl({"a": "hello", "b": "world"});

Google's Closure Templates is a natively-JavaScript templating system and a seemingly natural fit with NodeJS. Here are some instructions for integrating them.


Did you try PURE ?
If you give it a try, feel free to post any trouble you may face at the forum

While it was primarly designed for the browser, it works well with Jaxer and Rhino.

I don't know node.js yet but if you can cache some JS and functions in memory, the speed should be even more impressive.


There is a port of the Django templating engine to JavaScript. However, its not been updated for a long time but it may still have enough features.


Honestly, the best and most simple template engine for Node.js is (IMHO) Plates ( You might also want to check out the Flatiron MVC framework for Node.js (


You can use dojox.dtl of Note that dojo 1.7 can well run on NodeJS and perform as a server side library. If you're interested, I can give you a simple example.


You should be able to use mustache.js, if it doesn't work send me the issues and I'll get it fixed because I'm about to be using them in node.js anyway.

I know that it works without a DOM because a bunch of CouchDB standalone apps are using it in a Spidermonkey view server.


You should take a look at node-asyncEJS, which is explicitly designed to take the asynchronous nature of node.js into account. It even allows async code blocks inside of the template.

Here an example form the documentation:

    <% ctx.hello = "World";  %>
    <title><%= "Hello " + ctx.hello %></title>

    <h1><%? setTimeout(function () { res.print("Async Header"); res.finish(); }, 2000)  %></h1>
    <p><%? setTimeout(function () { res.print("Body"); res.finish(); }, 1000)  %></p>


You can try beardless (it's inspired by weld/plates):

For example:

{ post:
  { title: "Next generation templating: Start shaving!"
  , text: "TL;DR You should really check out beardless!"
  , comments:
    [ {text: "Hey cool!"}
    , {text: "Really gotta check that out..."}  ]

Your template:

<h1 data-template="post.title"></h1>
<p data-template="post.text"></p>
  <div data-template="post.comments" class="comment">
    <p data-template="post.comments.text"></p>


<h1>Next generation templating: Start shaving!</h1>
<p>TL;DR You should really check out beardless!</p>
  <div class="comment">
    <p>Hey cool!</p>
  <div class="comment">
    <p>Really gotta check that out...</p>

If you're looking for a minimalist approach to templates, you can check out JSON Template.

A more full-featured alternative is EJS. It's a bit more similar to something you'd get from Django.

Your mileage may vary for each of these - they're designed for a browser Javascript environment, and not Node.js.


Try Yajet too. ;-) It's a new one that I just released yesterday, but I'm using it for a while now and it's stable and fast (templates are compiled to a native JS function).

It has IMO the best syntax possible for a template engine, and a rich feature set despite its small code size (8.5K minified). It has directives that allow you to introduce conditionals, iterate arrays/hashes, define reusable template components etc.


I found hogan.js from Twitter and recommended by Tim O'Reilly on his site. I have no best practice with it, but I trust on Twitter and O'Reilly. You should try...


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.