# How to Modularize and Reuse Function Node Code in Node-RED?

**URL:** <https://discourse.nodered.org/t/how-to-modularize-and-reuse-function-node-code-in-node-red/94012>\
**Category:** General\
**Tags:** function-node\
**Created:** [19 December 2024 05:48 UTC](https://discourse.nodered.org/t/how-to-modularize-and-reuse-function-node-code-in-node-red/94012 "2024-12-19T05:48:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [19 December 2024 07:02 UTC](https://discourse.nodered.org/t/how-to-modularize-and-reuse-function-node-code-in-node-red/94012/3 "2024-12-19T07:02:23Z")

</div>

In the past I've used one of the following approaches:

### 1. Put the function into a subflow

#### Advantages:

- proper error handling using the catch node
- make use of node status
- export/import subflows for reuse in other Node-RED instances

#### Disadvantage:

- you might end up with many subflows cluttering the left palette bar

### 2. Use link-calls

#### Advantages:

- better organization
  - put your shared functions on a separate flow tabs --\> you can hide and/or lock flow tabs!
  - no cluttering of the palette bar

#### Disadvantage:

- error handling is more complicated
  - errors can't be caught by targeting the link-call node because you can't pass them to the link result node
  - you'd have to handle errors manually on each call side by evaluation for an `error` property... too much boilerplate for me 🙈

- no node status on the calling side

There was a discussing regarding the error handling with link-calls, but no conclusion has been reached: [Capturing errors caused inside link-call flows - #5 by kuema](https://discourse.nodered.org/t/capturing-errors-caused-inside-link-call-flows/80010/5)

That's why I prefer the subflow solution, because I like clean error handling using "try-catch" 🤓

---

_[View the full topic](https://discourse.nodered.org/t/how-to-modularize-and-reuse-function-node-code-in-node-red/94012)._
