# Module Import to settings.js Error

**URL:** <https://discourse.nodered.org/t/module-import-to-settings-js-error/59716>\
**Category:** General\
**Tags:** function-node\
**Created:** [11 March 2022 14:31 UTC](https://discourse.nodered.org/t/module-import-to-settings-js-error/59716 "2022-03-11T14:31:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecymb1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ecymb1/32/49640_2.png) [@ecymb1](https://discourse.nodered.org/u/ecymb1)\
**Post date:** [11 March 2022 14:31 UTC](https://discourse.nodered.org/t/module-import-to-settings-js-error/59716/1 "2022-03-11T14:31:08Z")

</div>

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:  
`moment:require('/usr/lib/node_modules/node-red/node_modules/moment/moment.js')`  
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.

Similar questions/methods:  
[Accessing Global Context from Storage](https://discourse.nodered.org/t/using-the-functionglobalcontext/36445)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 March 2022 14:40 UTC](https://discourse.nodered.org/t/module-import-to-settings-js-error/59716/2 "2022-03-11T14:40:04Z")

</div>

Have you tried simply adding it to the function setup tab?

alternatively, you could always install `node-red-contrib-moment` node & save the troubles.

---

<div class="post-metadata">

**Author:** ![ecymb1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ecymb1/32/49640_2.png) [@ecymb1](https://discourse.nodered.org/u/ecymb1)\
**Post date:** [11 March 2022 15:12 UTC](https://discourse.nodered.org/t/module-import-to-settings-js-error/59716/3 "2022-03-11T15:12:51Z")

</div>

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](https://nodered.org/docs/user-guide/writing-functions)

Within the function node i mentioned:

```auto
moment = global.get('moment');
today = moment(Date()).format('M/D/YY');

```

Within my settings.js file, i have the following uncommented:

```auto
functionGlobalContext: {
        // os:require('os'),
        // jfive:require("johnny-five"),
	moment:require('/usr/lib/node_modules/node-red/node_modules/moment')
        // j5board:require("johnny-five").Board({repl:false})
    },

```

Hope that clarifies it. Thanks again.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 March 2022 15:19 UTC](https://discourse.nodered.org/t/module-import-to-settings-js-error/59716/4 "2022-03-11T15:19:17Z")

</div>

I understood what you were asking but wanted to be sure you hadnt missed the obvious

e.g. using moment in a fucntion node

> [@Steve-Mcl](#):
>
> Have you tried simply adding it to the function setup tab?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e34b998b092c61f5e9811e0aefaae3f215ade2f3.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a3e0c0da56a3c96755ec225014d63acbd6fb322.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e631e2143a70f938f0172e617e48d20d0956ae2.png)

```auto
const m = moment(msg.payload);
msg.payload = m.format("yyyy/MM/DD")
return msg;

```

---

<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:** [10 May 2022 15:19 UTC](https://discourse.nodered.org/t/module-import-to-settings-js-error/59716/5 "2022-05-10T15:19:34Z")

</div>

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