# Calling npm module from the function node

**URL:** https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535
**Category:** General
**Created:** [20 October 2020 05:24 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535 "2020-10-20T05:24:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ded\_banzai](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ded_banzai/32/13179_2.png) [@ded\_banzai](https://discourse.nodered.org/u/ded_banzai)
#### Post date: [20 October 2020 05:24 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535/1 "2020-10-20T05:24:53Z")

</div>

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:

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

```

And here's my function:

```auto
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?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 October 2020 06:31 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535/2 "2020-10-20T06:31:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ded\_banzai](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ded_banzai/32/13179_2.png) [@ded\_banzai](https://discourse.nodered.org/u/ded_banzai)
#### Post date: [20 October 2020 06:40 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535/3 "2020-10-20T06:40:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ded\_banzai](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ded_banzai/32/13179_2.png) [@ded\_banzai](https://discourse.nodered.org/u/ded_banzai)
#### Post date: [20 October 2020 06:47 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535/4 "2020-10-20T06:47:39Z")

</div>

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

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

```

So it should work, but it doesn't

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 October 2020 06:51 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535/5 "2020-10-20T06:51:01Z")

</div>

> [@ded\_banzai](#):
>
> `wClock=global.get('worldClock')`

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

---

<div class="post-metadata">

### Author: ![ded\_banzai](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ded_banzai/32/13179_2.png) [@ded\_banzai](https://discourse.nodered.org/u/ded_banzai)
#### Post date: [20 October 2020 06:54 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535/6 "2020-10-20T06:54:02Z")

</div>

It worked! Thanks a lot!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [19 December 2020 06:54 UTC](https://discourse.nodered.org/t/calling-npm-module-from-the-function-node/34535/7 "2020-12-19T06:54:06Z")

</div>

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