I use node.js, express.js and pug/jade.
In my server I populate a view with a variable pageId.
I use this variable in my pug view with
script.
document.addEventListener('DOMContentLoaded', function () {
var pageId = '#{pageId}';
(...)
The problem is that I want this script code to be located in a separate file rather than in my view.
So I want to include the script with
script(src='js/my_script.js')
but then I am not able to get the value of the variable in the script.
How is this normally done? It seems wrong to send variables from the server to a script code in the view on the client side.
I guess it is irrelevant that I use pug.js, since the same problem must arise even in plain html.