Javascript Templating Language and Engine— Mustache.js with Node and Express

Image for post
Image for post

Javascript Templating

Mustache

Image for post
Image for post
As the name suggests, it was named mustache because the syntax resembles a Mustache. E.g. {{ placeholder }}
Mustache.render(“Hello, {{name}}”, { name: “Sherlynn” });
// returns: Hello, Sherlynn
Image for post
Image for post
Source: The Ultimate Mustache Tutorial

Mustache-Express

$ yarn add mustache-express
$ npm install mustache --save
Image for post
Image for post
Configure Mustache for use in your node-express application
Image for post
Image for post
Create a views folder + html view files
Image for post
Image for post
A simple hello.html file with “Hello {{name}}” mustache usage
res.render('hello', {"name": "Sherlynn"})
var nameObject = {"name": "Sherlynn"}res.render('hello', nameObject)
Image for post
Image for post
Hello {{name}}

Software Developer at @thoughtworks | Marathon Runner | Ex-Pharmacist Writing on Coding, Technology and Running

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store