How to handle data with template engine

Hello Comunity!!
Well i have a litle problem and i can’t fix it. So i came for help.

CASE 1: Work properly with my code, i mean .html and .js files separately.
CASE 2 and 3: Those are my failed attemps to send the same data from the server side to the browser side. In these case i use EJS so i put all the js code into the .ejs files (so now i have the html code and js code into the ejs file, for each page). I think that in this way my fetch doesn’t like it used to, because the response send me an error.

My question is: There is a way to send the data to my browser side using template engine? How it would be?