3

I am developing an application with the MEAN stack and am really not liking 'Jade'. I find myself just using an HTML to Jade translator a lot and would just rather write in HTML.

How do I not use Jade in an Express project?

Also, could someone explain what a templating engine is and why one is needed?

Tim
  • 284
  • 1
  • 4
  • 20
  • You're asking too many questions here. Please make this more specific. Research templating engines on your own first instead of just spitting out the question on SO. – djechlin Jan 16 '14 at 21:17
  • 2
    Check out spectrum's answer here: http://stackoverflow.com/questions/4529586/render-basic-html-view-in-node-js-express#answer-6960021 – skeggse Jan 16 '14 at 21:33

2 Answers2

2

You can set:

app.use(express.static(__dirname + '/public'));

in your config file instead to use just vanilla HTML.

As the previous response, templating engines allow you to set more dynamic content and write less code.

SkyOut
  • 390
  • 1
  • 10
  • then in my 'views' folder I can just use index.html instead of index.jade? – Tim Jan 16 '14 at 21:26
  • 1
    @Tim see my comment on your question. In short, no, this will just serve static pages from the `public` directory. – skeggse Jan 16 '14 at 21:35
1

Try EJS as it looks much more like HTML.

http://embeddedjs.com/

<ul>
<% for(var i=0; i<supplies.length; i++) {%>
   <li><%= supplies[i] %></li>
<% } %>
</ul>

You can render out HTML through the response object res.send and generate all the HTML in server side code

res.send('<html>...</html>');

Generally if you're displaying dynamic data rather than a static HTML page, people find it easier and more encapsulating to use a view engine such as EJS and bind the view to an object that contains all the dynamic data they want to display. This is an example of applying the Separation of Concerns design principle, which is considered good practice: http://en.wikipedia.org/wiki/Separation_of_concerns

Daniel Flippance
  • 7,734
  • 5
  • 42
  • 55
  • While using `ejs` works, it's also both the evaluative and filesystem overheads of installing a module that ultimately doesn't contribute much. – skeggse Jan 16 '14 at 21:34