Using the <%= %>
tag in EJS will escape the output, so {"application/octet-stream": ... }
is being turned into {"application/octet-stream": ... }
, resulting in JavaScript like this:
<script type="text/javascript">
var FileTypes = {"application/octet-stream":20,"audio/mpeg":12,"text/html":71};
</script>
So, you can see where the "Unexpected token &" is coming from. The solution is to use the <%- %>
tag, which won't escape the output:
<script type="text/javascript">
var FileTypes = <%- FileTypes %>;
// here -----^
</script>
...and will give you what you want:
<script type="text/javascript">
var FileTypes = {"application/octet-stream":20,"audio/mpeg":12,"text/html":71};
</script>