In my Express JS app, I am using ejs view engine, I want to pass variable to javascript file on client side.
This is my render:
return res.render('data/show', {
data: data
});
This is working for me:
<script>
var data = <%- JSON.stringify(data) %>;
console.log(data);
</script>
But my function is in separate .js file that I am including, when I am using the same code:
function gettingData() {
var data = <%- JSON.stringify(data) %>;
console.log(data);
}
I am getting syntax error:
Uncaught SyntaxError: Unexpected token <
Thank you in advance for any suggestions.