Skip to content
Advertisement

Express and ejs <%= to render a JSON

In my index.ejs I have this code:

JavaScript

In my node I have

JavaScript

However, on the page I obtain

JavaScript

and if I write

JavaScript

I obtain:

JavaScript

Is there a way to pass a JSON that will be JS readable?

Advertisement

Answer

Oh that was easy, don’t use <%=, use <%- instead. For example:

JavaScript

The first one will render in HTML, the second one will render variables (as they are, eval)

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement