# Common local library for managing javascript functions used in function nodes

**URL:** <https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065>\
**Category:** Core Development\
**Tags:** function-node\
**Created:** [30 September 2024 07:49 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065 "2024-09-30T07:49:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![psmtvdw](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@psmtvdw](https://discourse.nodered.org/u/psmtvdw)\
**Post date:** [30 September 2024 07:49 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/1 "2024-09-30T07:49:54Z")

</div>

I've stumbled on this old page:  
[Design: Function Library node · node-red/node-red Wiki · GitHub](https://github.com/node-red/node-red/wiki/Design%3A-Function-Library-node)

> We have seen a growing number of users who are inserting JavaScript into global context so it can be readily reused amongst the Function nodes in a flow. This is not a great developer experience and something we could improve.

Has there been any development around this since then? Am I overseeing another functionality that solves this problem? are Modules in the function node usable for managing my custom js code?

---

<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:** [30 September 2024 08:13 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/2 "2024-09-30T08:13:55Z")

</div>

Yes, you can now load packages direct to a function node.

---

<div class="post-metadata">

**Author:** ![psmtvdw](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@psmtvdw](https://discourse.nodered.org/u/psmtvdw)\
**Post date:** [30 September 2024 08:48 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/3 "2024-09-30T08:48:40Z")

</div>

Does this mean I have to publish my package to NPM to use this? Or can I use this mechanism also for local packages? After all, the purpose is to have an utility library of javascript functions for own use, not something that is of any value for other users.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 September 2024 08:53 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/4 "2024-09-30T08:53:24Z")

</div>

Hi @psmtvdw

The item you link to has not had anything done; the idea of having a reusable set of functions that can be easily reused.

Since then, as @TotallyInformation says, we have made it easier to use npm modules in the function node - but that is a different use case and does require modules to have been published to npm.

---

<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:** [30 September 2024 09:02 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/5 "2024-09-30T09:02:50Z")

</div>

> [@knolleary](#):
>
> does require modules to have been published to npm

I wonder if that might be a future upgrade? To allow any specifier for a package that is supported by npm? Then things could be installed from GitHub and even locally.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 September 2024 13:11 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/6 "2024-09-30T13:11:01Z")

</div>

> [@knolleary](#):
>
> does require modules to have been published to npm.

I can't try it at the moment, but if a package is installed manually from GitHub or file, can it then be used in a function even though it has not been published?

---

<div class="post-metadata">

**Author:** ![psmtvdw](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@psmtvdw](https://discourse.nodered.org/u/psmtvdw)\
**Post date:** [30 September 2024 13:41 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/7 "2024-09-30T13:41:21Z")

</div>

I've tested this, and the answer is yes (Tried both installing from local file and from a git repository). Manually updated the package file, ran npm install, add a module in a function node and it worked. It is an alternative to the approach of adding to the settings.js, but it doesn't really add much, except for a package file in the module where you can set a version number. You still need to manage your js functions outside node-red, hard to know from within the node-red editor which functions are available and what they do .

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 September 2024 14:00 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/8 "2024-09-30T14:00:27Z")

</div>

You can also save code to the function library and import it into a function node.

 ![Screenshot_20240930-145809](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab6d6d2a058deb979a1a12d837d58d5c9f9c85be.png)

---

<div class="post-metadata">

**Author:** ![psmtvdw](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@psmtvdw](https://discourse.nodered.org/u/psmtvdw)\
**Post date:** [30 September 2024 14:21 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/9 "2024-09-30T14:21:14Z")

</div>

Indeed, but this is not really the solution to the problem described above. This is useful in case you want to reuse a complete function node. But function nodes loaded from this library earlier will not be updated after updating the function in the library I suppose. In my opinion the current open and save to library functions are not really a library but more of a collection of snippets/examples. In case of a real library, all java script functions used in every function node will be updated after updating the source code, just like you would use a module.

---

<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:** [29 December 2024 14:21 UTC](https://discourse.nodered.org/t/common-local-library-for-managing-javascript-functions-used-in-function-nodes/92065/10 "2024-12-29T14:21:47Z")

</div>

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