# How to set the Function in Flow or Globally

**URL:** <https://discourse.nodered.org/t/how-to-set-the-function-in-flow-or-globally/12917>\
**Category:** General\
**Created:** [4 July 2019 15:56 UTC](https://discourse.nodered.org/t/how-to-set-the-function-in-flow-or-globally/12917 "2019-07-04T15:56:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamiloli.it](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@tamiloli.it](https://discourse.nodered.org/u/tamiloli.it)\
**Post date:** [4 July 2019 15:56 UTC](https://discourse.nodered.org/t/how-to-set-the-function-in-flow-or-globally/12917/1 "2019-07-04T15:56:23Z")

</div>

Hi, I am create the user-defined function into the function node; This function how to set to be flow or globally;I am try to used this function anywhere flow in to number of times; please guide me...

---

<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:** [4 July 2019 16:22 UTC](https://discourse.nodered.org/t/how-to-set-the-function-in-flow-or-globally/12917/2 "2019-07-04T16:22:45Z")

</div>

Create a subflow instead.

[https://nodered.org/docs/user-guide/editor/workspace/subflows](https://nodered.org/docs/user-guide/editor/workspace/subflows)  
Subflows : Node-RED

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [4 July 2019 16:36 UTC](https://discourse.nodered.org/t/how-to-set-the-function-in-flow-or-globally/12917/3 "2019-07-04T16:36:20Z")

</div>

@Steve-Mcl related question from my side, something I was wondering the other night. Say you have some code stashed in a function node, 1 input, 1 output with a commonly occurring kind of handling. Are there better solutions than either setting up that single function node as subflow, or writing a custom node to do it as to not clutter the subflows too much?

---

<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:** [4 July 2019 16:40 UTC](https://discourse.nodered.org/t/how-to-set-the-function-in-flow-or-globally/12917/4 "2019-07-04T16:40:57Z")

</div>

I have in the past stored function object(s) in flow/global but that means mostly using function nodes to access them.

No Biggie but not exactly the "node-red way" (imo).

You could of course make a multifunctional subflow and use properties of msg for parameters and `msg.topic` as the function name.  
Just be sure to use the self documenting features of the subnode to remind you how it works.

---

<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:** [4 July 2019 16:42 UTC](https://discourse.nodered.org/t/how-to-set-the-function-in-flow-or-globally/12917/5 "2019-07-04T16:42:42Z")

</div>

I tend to write a custom node only when additional libraries are required and/or many functions that would clutter subflow.
