Using Mustache Templating engine with Express

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

To use the Mustache templating engine in Express, you first install the mustache-express package

npm install mustache-express –save

and then add the require module…

setting up mustache

This sets up the “views” sub-folder to hold the mustache templates with files ending in file extension “html”.  I’ve put the “hello.html” template in there with this content…

mustache template

The “yourname” is a variable data that we pass to the template from the application by replacing the “send” call with the “render” call to the template name (without the file extension).  See code above.

Now when you run it, it will render…

template output