# Importing function from another node

**URL:** https://discourse.nodered.org/t/importing-function-from-another-node/15885
**Category:** General
**Created:** [25 September 2019 13:23 UTC](https://discourse.nodered.org/t/importing-function-from-another-node/15885 "2019-09-25T13:23:44Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)
#### Post date: [27 September 2019 04:51 UTC](https://discourse.nodered.org/t/importing-function-from-another-node/15885/6 "2019-09-27T04:51:17Z")

</div>

I have a similar solution that I often use, calling it the "module pattern". I keep my shared modules on the very first tab, triggered by a trigger node ('Inject once after...' option), so they get initialized first and put into global context.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/585e2dda936e5be936ca87e85baec529f85e086f.png)

The "module" (an example):

```auto
const util = (function () {
    'use strict';
    
    function add(a, b) {
        return a + b;
    }
    
    return {
        add: add
    };
    
}());

global.set('util', util);

```

It is wrapped in an IIFE so I can use strict mode, something you can't do in the function node itself.

In your function nodes you can use it the same way as yours, but with the benefit of having the code editable in the runtime, no restart required.

---

_[View the full topic](https://discourse.nodered.org/t/importing-function-from-another-node/15885)._
