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
That's why I prefer the subflow solution, because I like clean error handling using "try-catch"