Some of my recent posts and ramblings.

Replacing Jade and Stylus with Handlebars and Less in Express

Jade and Stylus are two of the most annoying things to work with in Node. I was setting up a new Expressjs project and it was a pain to work with those two. Maintaining the right indentations and writing html and css with indentation and it’s language was confusing to say the least. Surprisingly, it is actually very easy to replace them. I don’t know why most articles which go through setting up an Expressjs do not mention this more.

We will be replacing Jade with Handlebars and Stylus with Less and here is the code to make it happen

var handlebars = require('express-handlebars'),
    lessMiddleware = require("less-middleware"),
 app.set('views', path.join(__dirname, 'views'));
 app.engine('hbs', handlebars({extname:'.hbs', defaultLayout:'main'}));
 app.set('view engine', 'hbs');

 app.use(lessMiddleware(path.join(__dirname, 'public')));
 app.use(express.static(path.join(__dirname, 'public')));

Leave a Reply

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>