# Use function multiple times

**URL:** <https://discourse.nodered.org/t/use-function-multiple-times/7280>\
**Category:** General\
**Created:** [26 January 2019 18:51 UTC](https://discourse.nodered.org/t/use-function-multiple-times/7280 "2019-01-26T18:51:03Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [26 January 2019 19:30 UTC](https://discourse.nodered.org/t/use-function-multiple-times/7280/3 "2019-01-26T19:30:40Z")

</div>

> [@KoenH](#):
>
> Is it possible to use a function that i created multiple times on different places?

One approach would be to use the global.set() with the memory module.

1. store your function in a global variable:

```auto
global.set('sum', function(a, b) {
    return a + b;
}, 'memoryOnly');

```

1. use your function:

```auto
msg.payload = global.get('sum', 'memoryOnly')(2, 3);

return msg;

```

**Note: you need this setting in the settings.js:**

```auto
    contextStorage: {
        default: {
	          module:"localfilesystem"
        },
        memoryOnly: {
            module: "memory"
        }
    },

```

Flow:

```auto
[{"id":"4ac1d184.c4df1","type":"inject","z":"66646ca8.e97654","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":2960,"wires":[["f3f7db1.61ac128"]]},{"id":"f3f7db1.61ac128","type":"function","z":"66646ca8.e97654","name":"","func":"global.set('sum', function(a, b) {\n return a + b;\n}, 'memoryOnly');","outputs":1,"noerr":0,"x":340,"y":2960,"wires":[[]]},{"id":"1b0cf5f7.27cc2a","type":"function","z":"66646ca8.e97654","name":"","func":"msg.payload = global.get('sum', 'memoryOnly')(2, 3);\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":3020,"wires":[["da372639.45dec8"]]},{"id":"ddabba53.8d96e8","type":"inject","z":"66646ca8.e97654","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":3020,"wires":[["1b0cf5f7.27cc2a"]]},{"id":"da372639.45dec8","type":"debug","z":"66646ca8.e97654","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":3020,"wires":[]}]

```

---

_[View the full topic](https://discourse.nodered.org/t/use-function-multiple-times/7280)._
