How to Debug EJS code in Chrome/Safari

Ankur Aggarwal picture Ankur Aggarwal · Mar 20, 2014 · Viewed 9.1k times · Source

I am using EJS templates with CanJS and are looking for a way to debug my EJS code. Currently firebug can show me the syntax errors in EJS but in other browsers, I am not able to see anything.I need to go through my EJS file very carefully to solve the errors. I searched on web and found out about ejs_fulljslint https://code.google.com/p/embeddedjavascript/ , but not able to run this properly. I included the script into my HTML file but still wasn't getting any console errors. I am not able to find a demo of debugging on web.

Can anyone tell me how to debug my EJS code. If you can provide me any example, that will be highly appreciated.

Answer

Coz picture Coz · Apr 13, 2014

In the end, EJS just translates to JavaScript and therefore just placing a debugger; statement where you need it and opening developer tools, might do the trick for you. For example, to check on the i variable in a for loop you would place your debugger; like this:

<script type="text/ejs" id="todoList">
  <% for(var i = 0; i < todos.length; ++i) { %>
    <% debugger; %>
    <li><%= this[i].attr('description') </li>
  <% } %>
</script>