I tried to load a module (called 'moment') into the function node. Following the official documentation, I loaded it into settings.js file by adding:
to the functionGlobalContext property. Then tried to load it into the function node through:
moment = global.get('moment.js');
but i keep getting the error:
"TypeError: moment is not a function"
Any (and all) help would be greatly appreciated.
Accessing Global Context from Storage
Have you tried simply adding it to the function setup tab?
alternatively, you could always install
node-red-contrib-moment node & save the troubles.
Thanks for getting back so fast.
I think you misunderstood what i did, let me clarify it:
I have the node-red-contrib-moment module installed in my palette, but to mention it inside the function node I had to follow the following instructions (you might need to scroll down):
Using the functionGlobalContext option
Within the function node i mentioned:
moment = global.get('moment');
today = moment(Date()).format('M/D/YY');
Within my settings.js file, i have the following uncommented:
Hope that clarifies it. Thanks again.
I understood what you were asking but wanted to be sure you hadnt missed the obvious
e.g. using moment in a fucntion node
const m = moment(msg.payload);
msg.payload = m.format("yyyy/MM/DD")
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.