31

I learnt that JADE is a template language and it is preferred engine for express.

What are the advantages of using JADE instead of html ? Is it possible to use html directly instead of using jade ?

Vinoth
  • 5,687
  • 11
  • 44
  • 56

2 Answers2

21

Jade has a cleaner, more readable syntax and comes with filters and helpers: https://github.com/visionmedia/jade#a7

If you're going to migrate HTML files to jade, this converter might come handy: http://html2jade.aaron-powell.com/

...but you can also use HTML.

app.set('view engine', 'html');

http://expressjs.com/guide.html#view-rendering

I'm using EJS ( http://code.google.com/p/embeddedjavascript/) as the rendering engine in my express app, but keep a .html suffix on the template files like this:

app.set('view engine', 'html');
app.register('.html', require('ejs'));

(requires ejs be installed, which you can easily do via npm install ejs)

gherkins
  • 14,603
  • 6
  • 44
  • 70
  • I've been coding up html for *years* and recently switched to jade and loving it. Just then I went to write out some html and totally forgot the syntax!!! I'm using jade whenever I can! – James Jul 22 '16 at 11:40
9

As a templating engine, it's all about syntax. You type faster and it improves readability, which means maintainability and productivity. Some of them have better features than others, but in the end it's often a matter of taste.

Express support a lot of templating engines available with nodejs : http://expressjs.com/guide/using-template-engines.html

Which template engines does Express support? Anything that can conform with the (path, locals, callback) signature. To normalize template engine interfaces and caching it's recommended to check the consolidate.js project for support. Unlisted template engines may still support the Express signature.

You should check the consolidate.js project, there is some integration examples with Express and gives a good overview of all the templating engines available for node. The choice is up to you, regarding your needs.

Adrien Schuler
  • 2,395
  • 1
  • 21
  • 32