Calling npm module from the function node

I am trying to use world-clock npm module within function node for the first time.
So, I installed module first, added one to the settings.js:

    functionGlobalContext: {
        worldClock:require('world-clock'),
    },

And here's my function:

const wClock=global.get('worldClock');
msg.payload=wClock.today('SYSTEM').toString();
return msg;

Which returns "TypeError: wClock.today is not a function"
typeof(wClock.today) returns the same, but typeof(wClock) returns "function".
What did I do wrong?

If wClock is a function then you cannot say wClock.property, it must be wClock(something)`.

Absolutely. But I import the module. That's what makes it weird.

Here's an example from the world-clock npm node documentation:

const clock = require('world-clock')()
clock.today('SYSTEM').toString() 

So it should work, but it doesn't

Looking at the docs I think you want
wClock=global.get('worldClock')()

It worked! Thanks a lot!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.