I'm trying to work with Google's example code: PhotoFrame. It is built with node.js, expressjs, jQuery, etc. I need to pass a variable -- let's call it myString -- from app.js to one of the .js files -- let's call it myScript.js. I've tried at least a dozen approaches that I found at StackOverflow and elsewhere. None has worked.
Some folks have said "just use a global, even though they're 'BAD'. In app.js you:
global.myStringGlobal = myString
and in myScript you:
var myStringLocal = myStringGlobal;
Doesn't work: myStringGlobal is undefined.
Some folks say: code a little object in app.js and module.export it. Them require it in myScript. Doesn't work: require is undefined in myScript. In fact, since myScript and myOtherScripts run in the browser, require is simply un-available.
Some folks say code this in app.js:
res.render(page, {myString: myString});
Others say "No, that sends myString to the html renderer; not to myString. They're correct.
I won't drag this out by telling you the other ways I tried in vain.
This question has been asked and answered many times in various ways, but none of the answers work -- anymore? or who knows why?
So I ask again: does anyone know how to pass a variable from the node.js app.js script to some myScript.js file?