I'm trying to access a global function I created in the Settings.js file.
I placed my function "testGlobalFunction" in Settings.js under "functionGlobalContext:":
functionGlobalContext: {
// os:require('os'),
global.testGlobalFunction = function(){
let x = {payload:'Returned Value'}
return x;
}
},
Then I restarted Node.js.
In the Function-node I tried several ways to access it;
var testGlobalFunction=global.get('testGlobalFunction')
var x= global.testGlobalFunction()
node.warn(x)
return x;
Or
var x= global.testGlobalFunction()
node.warn(x)
return x;
and using the settings to import module 'testGlobalFunction()'.
In each case I get an error saying that it can't find the function.
Well that little ":" certainly makes a difference; everything works now.
Regarding the log-file; where is it? There're no logs in the .node-red folder, or in Program Files. The only log files I've found are in npm-cache, buried in appdata, and they are not the node-red logs.
BTW: thanks for catching the error.
Also, will a function placed in settings.js be able to access suncalc, for example:
var gate
var location = { latitude: 40.392, longitude: -74.1843 };
var times = suncalc.getTimes(new Date(), location.latitude, location.longitude);
gate = {
sunrise: times.sunrise.getTime(),
sunset: times.sunset.getTime(),
now: new Date().getTime()}
I import using the function-node setting; how do I import it just using java-script?
I've tried:
const suncalc = require('suncalc');
Says 'require' undefined
and
import suncalc from 'suncalc';
Says: Cannot use import statement outside a module
Neither seem to resolve 'suncalc'
ALL TESTING BEING DONE IN A FUNCTION-NODE: NOT IN SETTING.JS.