# Import your own functions into a function node

**URL:** <https://discourse.nodered.org/t/import-your-own-functions-into-a-function-node/78500>\
**Category:** General\
**Created:** [17 May 2023 16:49 UTC](https://discourse.nodered.org/t/import-your-own-functions-into-a-function-node/78500 "2023-05-17T16:49:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gylim78](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gylim78/32/69495_2.png) [@gylim78](https://discourse.nodered.org/u/gylim78)\
**Post date:** [17 May 2023 16:49 UTC](https://discourse.nodered.org/t/import-your-own-functions-into-a-function-node/78500/1 "2023-05-17T16:49:05Z")

</div>

Hi All,

Is there any easy way that I can import my own functions and use them inside a function node?

So for example I have a function A that will take in a value do some logic and return a value B. I would like to be able to use this function A in multiple the function nodes across the project. So if needed, I could edit the logic of function A and then it returns a new value C and this new logic can be applied across all the function nodes.

Just wondering how this can be done easily and how the editing of the function A can be done easily as well.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 May 2023 17:01 UTC](https://discourse.nodered.org/t/import-your-own-functions-into-a-function-node/78500/2 "2023-05-17T17:01:46Z")

</div>

There are at least a couple of ways.

The "traditional" way is to set your function up in a node.js module. This means simple "exporting" the function and doing a `require` of that module in Node-RED's settings.js file.

mymodule.js

```auto
module.exports = {

   function myfn1(someParam) {
      // .... my code ...
   }

   // ... more functions if you want to ...

}

```

In the globals section of settings.js

```auto
    myStuff = require('./mymodule'), // this assumes you put the file in the same folder as settings.js

```

THen in your function node, you can do:

```auto
const myStuff = global.get('myStuff')

myStuff. myFn1(blah)

```

If you want shorted function names:

```auto
const { myFn1 } = global.get('myStuff')

myFn1(blah)

```

---

<div class="post-metadata">

**Author:** ![gylim78](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gylim78/32/69495_2.png) [@gylim78](https://discourse.nodered.org/u/gylim78)\
**Post date:** [18 May 2023 03:41 UTC](https://discourse.nodered.org/t/import-your-own-functions-into-a-function-node/78500/3 "2023-05-18T03:41:38Z")

</div>

Thank you so much for the reply.  
I will try it out 😀

---

<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:** [19 May 2023 12:51 UTC](https://discourse.nodered.org/t/import-your-own-functions-into-a-function-node/78500/4 "2023-05-19T12:51:11Z")

</div>

The more "low code" way (and runtime editable) would be to put your common function into a function node and "call" it using the link-call node.

---

<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:** [18 July 2023 12:51 UTC](https://discourse.nodered.org/t/import-your-own-functions-into-a-function-node/78500/5 "2023-07-18T12:51:42Z")

</div>

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