I need to have some config object both in the node app and in the browser. Here is the path and the content of the config:
path: [app]/public/js/config.js
content:
var config = {
"foo": "bar",
"num": 42,
"list": ["a","b","f"]
};
var isBrowser=new Function("try {return this===window;}catch(e){ return false;}");
if(!isBrowser) {
module.exports = config;
}
In my html I just add a script element and it works fine:
<script src="/js/config.js"></script>
In node app however I do not seem to have imported the object and I get an empty object:
var config = require('./public/js/config.js');
console.log('config:', config); // gives config: {}
What am I doing wrong?